Ask Your Question

Dragoen's profile - activity

2013-12-09 20:36:40 -0600 received badge  Editor (source)
2013-12-09 20:34:45 -0600 answered a question Measuring the dimension(height and width) of an object.

I rewrite this program ...! I am using OpenCV 2.4.3

see this code:

#include <opencv/ highgui.h>
#include <opencv/ cv.h>
#include <opencv/ cxcore.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace cv;
using namespace std;

int main(int, char**) { 
    Mat src; Mat src_gray;
    int thresh = 100;
    int max_thresh = 255;
    RNG rng(12345);

    cv::Mat frame; 
    VideoCapture capture;
    capture.open(0);

    while(true) { 

        capture.read(frame);
        Mat threshold_output;
        vector<vector<Point> > contours;
        vector<Vec4i> hierarchy;

        cvtColor( frame,src_gray, CV_BGR2GRAY ); // produces out2, a one-channel image (CV_8UC1)
        blur( src_gray, src_gray, Size(5,5) );

        threshold( src_gray, threshold_output, thresh, max_thresh, CV_THRESH_BINARY_INV);

        findContours( threshold_output, contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

        /// Find the rotated rectangles
        vector<RotatedRect> minRect( contours.size() );

  for( int i = 0; i < contours.size(); i++ )
     { 
         minRect[i] = minAreaRect( Mat(contours[i]) );
     }

    /// Draw contours + rotated rects + ellipses
    Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
  for( int i = 0; i < contours.size(); i++ )
     {
       Scalar color = Scalar( rng.uniform(0,0), rng.uniform(0,0), rng.uniform(250,250) );
       // contour
       drawContours( drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
       // rotated rectangle

       Point2f rect_points[4]; minRect[i].points( rect_points );

       for(int j = 0; j < 4; j++ )
       line( frame, rect_points[j], rect_points[(j+1)%4], color, 1, 8 );
     }
/// Show in a window 
  namedWindow( "Contours", CV_WINDOW_AUTOSIZE ); 
  imshow( "Contours", frame );

    int c= cvWaitKey(10);
    if ((char) c==72) break;
}
return 0;
}

C:\fakepath\main.jpg I hope this can help anyone who needs ..! : D

2013-11-18 23:52:06 -0600 received badge  Critic (source)
2013-10-02 02:26:12 -0600 commented question Measuring the dimension(height and width) of an object.

Could you post the results and source code here?I'm also having the same problem,

2013-10-02 02:23:43 -0600 answered a question Measuring the dimension(height and width) of an object.

I'm having the same problem as you, so I wonder, has this problem been solved?