cvWatershed () takes two logic Iplimage * src_image and CVArr * markers.
Does anyone need to break my image on the basis of my touch since the reasoning of the markers, so on the basis of my touch the marker array can be made in real time and then cvWatershed Should be called ..?
I've used the watershed.cpp demo. I want to roughly portray some parts of the image and I want to get that selected part along with that black part. But I am not getting the desired output, please check the code and tell me where I have a mistake ... #include "stdafx.h" #include "cv.h" #include "Highgui.h" # included and lieutenant; Stdio.h & gt; # Include & lt; Stdlib.h & gt; IplImage * Marker_mask = 0; IplImage * Marker = 0; IplImage * img0 = 0, * img = 0, * img_gray = 0, * wshed = 0; CvPoint prev_pt = {-1, -1}; Zero on_mouse (int event, int x, int y, int flags, zero * absolute) {if (! Img) return; If (incident == CV_AVCLLUUTUP ||! (Flags and CV_AVCNFLAG_LBUTUN)) prev_pt = cvpint (-1, -1); Else if (event == CV_EVENT_LBUTTONDOWN) prev_pt = cvPoint (x, y); And if (incident == CV_AVICMUMEEVE & amp; (Flags and CV_AVCNFLAG_LBUTN)) {CVPint PT = CVPS (X, Y); If (prev_pt.x & lt; 0) prev_pt = pt; CvLine (Marker_mask, PARTTPT, PT, CVSLLL (255), 5, 8, 0); CvLine (IMG, PARTTPT, PT, CVSLLL (255), 5, 8, 0); Prev_pt = pt; CvShowImage ("Image", IMG); }} Int main (int argc, char ** argv) {char * filename = argc & gt; = 2? Argv [1]: (four *) "D: test / .jpg"; CVRNG RNG = CVRNG (-1); If ((img0 = cvLoadImage (file name, 1)) == 0) return 0; \ N "" \ tESC - \ n "" \ tESC leave program \ n "" - Restore original image \ n "" \ tw or enter - Watershed algorithm \ n "" \ t \ t (before running it , Roughly mark the areas located on the image) \ n "" \ t (before that, several markers on the image are outlined) \ n "); CvNamedWindow (" image ", 1); CvNamedWindow (" Watershed Transforms ", 1); Img = cvCloneImage (img0); Img_gray = CVClone image (IMG0); wshed = cvCloneImage (img0); marker_mask = cvCreateImage (cvGetSize (IMG), 8, 1); marker = cvcitize (I CVCVTColor (IMG, Marker_mask, CV_BGR2GRAY); CvCvtColor (Marker_Mask, IMG_Gray, CV_GRAA2 BGR); CvZero (Marker_Mask); Civisero (Vested); CvShowImage ("Image", IMG); CvShowImage ( "Watershed Transform", wshed); CvSetMouseCallback ("image", on_mouse, 0); for (;;) {int c = cvWaitKey (0); if ((four) C == 27) break; if ((Four ) C == 'R') {cvZero (marker_mask); CVCCP (IMG 0, IMG); CvShowImage ("Image", IMG); } If ((four) C == 'w' || (four) C == '\ n') {CvMemStorage * storage = cvCreateMemStorage (0); CVSeq * pattern = 0; CvMat * color_tab; Int i, j, comp_count = 0; CvFindContours (Marker_Mask, Storage, and Shapes, Size (CVcintor), CV_UTRTICCOPP, CV_CNAAPANAPPXAFILE); CvZero (marker); (; Contours! = 0; contours = contours- & gt; h_next, comp_count ++) {cvDrawContours (marker, shape, cvScalarAll (comp_count + 1), cvScalarAll (comp_count + 1), -1, -1, 8, cvPoint (0, 0)); } Color_tab = cvCreateMat (1, comp_count, CV_8UC3); For (i = 0; i
Comments
Post a Comment