opencv - HSV segmentation based on mouse click -


i trying basic image segmentation. thereshold values hsv determined pixel value mouse clicked. cannot work. here wrote far:

#include <iostream> #include "opencv2/opencv.hpp" #include <cv.h> #include "opencv/highgui.h"  using namespace std; using namespace cv;  mat edges,frame,bw,hsv,dst,src_gray,probabilistic_hough, hsv_image; int h=110,s=40,v=140; int border=80; int linethreshold=180,linelengthslider=30,linegapslider=3, ht_threshold=10; int min_threshold = 50;  void printhsvvalues(int event, int x, int y, int, void* ); void changeborder( int, void* );  scalar hsvlow(0,0,0),hsvhigh(180,255,255);  int c=0;  void printhsvvalues(int event, int x, int y, int, void* );  int main ( int argc, char **argv ) {     videocapture cap(1);      namedwindow("edges",1);     namedwindow("segmented",1);      setmousecallback( "edges", printhsvvalues, 0 );      while (c != 'q') {         cap >> frame;         imshow("edges",frame);         c= (char)waitkey(100);     }      return 0; }  void  printhsvvalues(int event, int x, int y, int, void* ){      int loop;     float change;      if( event == event_lbuttondown ) {         cvtcolor(frame, hsv_image, cv_bgr2hsv);         vec3b p = hsv_image.at<float>(y,x);         (loop=0;loop<3;loop++) {              change=p[loop]*0.01;              hsvlow[loop]  = p[loop] - change;              hsvhigh[loop] = p[loop] + change;         }         inrange( hsv_image, hsvlow,hsvhigh,bw);         imshow("segmented",bw);     } } 

where messing up? in advance.

dy.

you not accessing mat-values correctly. image has 3-channels correctly assigned variable type vec3b, yet retrieve floatvalue image. correct way be:

vec3b p = hsv_image.at<vec3b>(y,x); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -