Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV 2.4.3 rectangle detection

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(); };

OpenCV 2.4.3 rectangle detection

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>

#include<opencv\cv.h>

#include<opencv\highgui.h>

#include<iostream>

using namespace cv;

cv; using namespace std;

std; using namespace cv;

cv; /// Global variables

variables Mat src, src_gray;

src_gray; Mat dst, cdst, ldst, detected_edges;

vector<vec4i> lines;

detected_edges; vector<Vec4i> lines; int edgeThresh = 1;

1; int const lowThreshold = 5;

5; int const maxThreshold = 200;

200; int ratio = 3;

3; int kernel_size = 3;

3; char* window_name1 = "Edge Map";

Map"; char* window_name2 = "Line Map";

int main()

{

Map"; int main() { //Load boxes.bmp into a matrix

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

); //convert boxes.bmp into grayscale

grayscale cvtColor( src, src_gray, CV_BGR2GRAY );

); /// Reduce noise with a kernel 3x3

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

); /// Canny detector

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

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

result src.copyTo( dst, detected_edges);

detected_edges); cvtColor( dst, cdst, CV_BGR2GRAY );

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

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

{ int x1 = lines[i][0];

lines[i][0]; int x2 = lines[i][2];

lines[i][2]; int y1 = lines[i][1];

lines[i][1]; int y2 = lines[i][3];

lines[i][3]; line( cdst, Point(x1, y1),

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

} imshow( "Source", src );

); imshow( "Detected Lines", cdst );

); waitKey(); };

};