"Exercise 5.7" cvcopy, thresholding, mask images, ROI, COI

Source: Internet
Author: User

Outline
Topic Requirements
Program code
Result picture
Homilies Miao DAO

Title Requirements:

Use the mask generated by exercise 6. Load a location map and use this mask in cvcopy:

A, copy the location map to a new image, copy only the portion of the mask that has a value not equal to 0.

B. Copy the mouse image to the location image.

Program code:

1 //OpenCVExerciseTesting.cpp: Defines the entry point of the console application. 2 //3 //d:\\work\\work_programming\\source\\image\\lena.jpg4 5 6#include"stdafx.h"7#include <cv.h>8#include 9#include <iostream>Ten using namespaceCV; One using namespacestd; A  - //function declaration---->-->--->-->--->-->--->// -  the //<--<--<--<--<--<--<--<--<--Function Declaration// -  -  - int_tmain (intARGC, _tchar*argv[]) + { -     Const Char* FileName1 ="d:\\work\\work_programming\\source\\image\\opencvexerciseimage\\ 5th chapter \ \ landscape. jpg"; +     Const Char* Filemask ="d:\\work\\work_programming\\source\\image\\opencvexerciseimage\\ 5th Chapter \\ExerciseResult_5-6.PNG"; AIplimage * Src1 =cvloadimage (fileName1, cv_load_image_grayscale); atIplimage * Imgmask =cvloadimage (Filemask, cv_load_image_grayscale); - assert (SRC1); - assert (Imgmask); -       -Cvnamedwindow ("Original Image",0);  -Cvnamedwindow ("Topic _a",0); inCvnamedwindow ("Topic _b",0); -  toCvshowimage ("Original Image", SRC1); +       -     //---------------------------A: Start--------------------------------// theCvthreshold (Imgmask, Imgmask, -,255, cv_thresh_binary); *  $ Panax NotoginsengIplimage * Imgcopy =cvcloneimage (SRC1); - Cvzero (imgcopy); the  +     //The area of interest must be set to ensure that the input image, output image, mask image roi, COI type and size are the same, or error ACvrect rect = Cvrect (0,0, Imgmask->width, imgmask->height); the Cvsetimageroi (SRC1, rect); + Cvsetimageroi (imgcopy, rect); -  $ cvcopy (Src1, imgcopy, imgmask); $  - Cvresetimageroi (imgcopy); - Cvresetimageroi (SRC1);  the  -Cvshowimage ("Topic _a", imgcopy);Wuyi  the     //---------------------------A: End--------------------------------//     -  Wu     //---------------------------B: Start--------------------------------// -Cvthreshold (Imgmask, Imgmask, -,255, cv_thresh_binary); About  $  -Iplimage * Imgcopy_b =cvcloneimage (SRC1); -  - Cvsetimageroi (Imgcopy_b, rect); A cvcopy (Imgmask, imgcopy_b,imgmask); + Cvresetimageroi (imgcopy_b); the  -  $Cvshowimage ("Topic _b", imgcopy_b); the  the     //---------------------------B: End--------------------------------//     the  theCvwaitkey (0); -  inCvreleaseimage (&src1); theCvreleaseimage (&imgmask); theCvreleaseimage (&imgcopy); AboutCvreleaseimage (&imgcopy_b); the  theCvdestroywindow ("Original Image");  theCvdestroywindow ("Topic _a"); +Cvdestroywindow ("Topic _b"); -  the     return 0;Bayi } the   

Result Picture:

Homilies Miao DAO:

Cvcopy Use precautions: must ensure that the input image, output image, mask image roi, COI type and size of the same, or error, you can set the area of interest to achieve this purpose

"Exercise 5.7" cvcopy, thresholding, mask images, ROI, COI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.