Ask Your Question
1

OpenCV 2.4.3 rectangle detection

asked 2013-02-04 14:17:12 -0600

donald83180 gravatar image

updated 2013-02-04 14:43:51 -0600

Blockquote

I have to take a bmp file with multiple rectangles and determine corner points and angle of rotation. I've started with a canny and a hough transform, but can't seem to determine the corners to continue. Below is what I have written so far. Any guidance in the right direction would be greatly appreciated.

#include<opencv\cv.h>

#include<opencv\highgui.h>

#include<iostream>

using namespace cv;

using namespace std;

using namespace cv;

/// Global variables

Mat src, src_gray;

Mat dst, cdst, ldst, detected_edges;

vector<Vec4i> lines;

int edgeThresh = 1;

int const lowThreshold = 5;

int const maxThreshold = 200;

int ratio = 3;

int kernel_size = 3;

char* window_name1 = "Edge Map";

char* window_name2 = "Line Map";



int main()

{

//Load boxes.bmp into a matrix

src = imread( "boxes.bmp",1 );

//convert boxes.bmp into grayscale

cvtColor( src, src_gray, CV_BGR2GRAY );

/// Reduce noise with a kernel 3x3

blur( src_gray, detected_edges, Size(3,3) );

/// Canny detector

Canny( detected_edges, detected_edges, lowThreshold, maxThreshold, kernel_size );

/// Using Canny's output as a mask, we display our result

src.copyTo( dst, detected_edges);

cvtColor( dst, cdst, CV_BGR2GRAY );

HoughLinesP( cdst, lines, 25, CV_PI/180, 1, 0, 0);

for( size_t i = 0; i < lines.size(); i++ )
{

int x1 = lines[i][0];

int x2 = lines[i][2];

int y1 = lines[i][1];

int y2 = lines[i][3];

line( cdst, Point(x1, y1),

Point(x2, y2), Scalar(255,255,255), 1, 8 );
}

imshow( "Source", src );


imshow( "Detected Lines", cdst );


waitKey();
};
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-02-05 03:15:45 -0600

Guanta gravatar image

This blog-post may help you by detecting your boxes: http://opencv-code.com/tutorials/automatic-perspective-correction-for-quadrilateral-objects/ . Alternatively a Harris-Corner Detection should also give you your points of interest.

edit flag offensive delete link more

Comments

@donald83180 How did you calculate the angle rotation?

pradeep_kb gravatar imagepradeep_kb ( 2016-02-02 10:05:12 -0600 )edit
LBerger gravatar imageLBerger ( 2018-09-02 07:45:35 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2013-02-04 14:17:12 -0600

Seen: 20,134 times

Last updated: Feb 05 '13