Ask Your Question
0

Intensity value based tracking

asked 2014-05-02 11:13:57 -0600

XYZ gravatar image

updated 2014-05-02 11:58:57 -0600

I want to draw a rectangle in opencv according to the pixel intensity i.e. i don't want to give a static values to cvRectangle like cv::point1 or cv::point2. I want that whenever specific intensity value is encountered it draws a rectangle around that object. I got a sample like this but it's not what i want how should i modify this

pMOG->operator()(frame, fgMaskMOG);

while(frame.data!=NULL)

 {
     for(int i=0;i<frame.row;i++)
     {
         for(int j=0;j<frame.col;j++)
         {
     if(frame.at<uchar>(i,j)=='0')
         //std::vector<Rect> frame;
         cv::rectangle(frame,                    // the dest image 
          cvPoint(100, 100),      // top left point 
          cvPoint(300, 30),       // bottom right point 
          cvScalar(255, 0, 0, 0), // the color; blue 
          3, 8, 0);               // thickness, line type, shift 

 }
     }
edit retag flag offensive close merge delete

Comments

could you edit that post, and format the code properly ?

berak gravatar imageberak ( 2014-05-02 11:56:22 -0600 )edit

Is it better now??

XYZ gravatar imageXYZ ( 2014-05-02 11:59:58 -0600 )edit

yes, a lot ;)

berak gravatar imageberak ( 2014-05-02 12:13:17 -0600 )edit

sorry, but I don't think that I understand your question properly: do you want to draw a rectangle _around a pixel of certain value_ or around an _object_? It the latter one, how do you get/define that _object_?

AR0x7E7 gravatar imageAR0x7E7 ( 2014-05-03 09:38:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-05-04 02:45:35 -0600

Philippe gravatar image

There is fantastic tracking example (extracted into your samples directory when you installed opencv) called objecttracking. 1) it converts to image from RGB to HSV - cvtColor(imageRGB,imageHSV,COLOR_BGR2HSV); 2) it extracts all sections that match the required HSV requirement - in your case intensity only inRange(imageHSV,Scalar(H_MIN,S_MIN,V_MIN),Scalar(H_MAX,S_MAX,V_MAX),imagethreshold); 3) It uses a morphological function (erode and dilate) to clean the image of 'noise' 4) It then uses find contours to create rectangles around all parts of the image that match your threshold (findContours(imagetemp,contours,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE );

Hope I understood your question....

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-05-02 11:13:57 -0600

Seen: 183 times

Last updated: May 04 '14