detect a irregular shape with opencv/ c++
up vote
0
down vote
favorite
I want to recognize the shape/mark shown in picture 1 highlighted shape (green border)
The scanned object resembles a bridge.
Unfortunately, I don't know how to detect the particular shape.
Picture 2 shows the original RGB picture. 2.Original Image
I edit it with the edge detection "cv::Canny" and the contouring "cv::findContours" (3.Edge detection results).
From this point on I don't know what to do.
I use opencv 3.4.2 and libfreenect2 in c++.
I use the kinect v2 for the recording.
The code section calls the image (3.) and edits it using "findContours". However, only the outer rectangle is displayed. But I would like to display the whole form as in picture (1). Unfortunately I don't have any ideas how to do this.
I would be very happy about help. Feel free to send some code examples.
Thank you
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
imwrite ("Canny.png", dst);
image=imread ("Canny.png");
Mat converted (image.rows, image.cols, CV_8UC1);
Mat dat (image.rows, image.cols, CV_8UC1, Scalar ::all(0));
cvtColor(image, converted, COLOR_BGR2GRAY,1);
dilate(converted, converted, Mat(), Point(-1.5,-1.5));
threshold (converted, converted,25, 255, THRESH_BINARY);
//findContours (converted, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
findContours (converted, contours,hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
// Mat drawing =Mat::zeros (converted.size(), CV_8UC3);
for (int i=0; i<contours.size(); i++)
{
double a= contourArea (contours[i], false);
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i;
bounding_rect=boundingRect (contours[i]);
}
}
Scalar color (255,255,255);
drawContours (dat, contours, largest_contour_index, color, CV_FILLED,8,hierarchy);
rectangle (image, bounding_rect , Scalar (0,255,0),1,8,0);
imshow("dat", image);
imshow ("largestContour", dat);
imwrite("largestContour.png", image);
imwrite("dat.png", dat);
c++ opencv object-detection shapes kinect-v2
add a comment |
up vote
0
down vote
favorite
I want to recognize the shape/mark shown in picture 1 highlighted shape (green border)
The scanned object resembles a bridge.
Unfortunately, I don't know how to detect the particular shape.
Picture 2 shows the original RGB picture. 2.Original Image
I edit it with the edge detection "cv::Canny" and the contouring "cv::findContours" (3.Edge detection results).
From this point on I don't know what to do.
I use opencv 3.4.2 and libfreenect2 in c++.
I use the kinect v2 for the recording.
The code section calls the image (3.) and edits it using "findContours". However, only the outer rectangle is displayed. But I would like to display the whole form as in picture (1). Unfortunately I don't have any ideas how to do this.
I would be very happy about help. Feel free to send some code examples.
Thank you
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
imwrite ("Canny.png", dst);
image=imread ("Canny.png");
Mat converted (image.rows, image.cols, CV_8UC1);
Mat dat (image.rows, image.cols, CV_8UC1, Scalar ::all(0));
cvtColor(image, converted, COLOR_BGR2GRAY,1);
dilate(converted, converted, Mat(), Point(-1.5,-1.5));
threshold (converted, converted,25, 255, THRESH_BINARY);
//findContours (converted, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
findContours (converted, contours,hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
// Mat drawing =Mat::zeros (converted.size(), CV_8UC3);
for (int i=0; i<contours.size(); i++)
{
double a= contourArea (contours[i], false);
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i;
bounding_rect=boundingRect (contours[i]);
}
}
Scalar color (255,255,255);
drawContours (dat, contours, largest_contour_index, color, CV_FILLED,8,hierarchy);
rectangle (image, bounding_rect , Scalar (0,255,0),1,8,0);
imshow("dat", image);
imshow ("largestContour", dat);
imwrite("largestContour.png", image);
imwrite("dat.png", dat);
c++ opencv object-detection shapes kinect-v2
Please, take a moment to proof-read your question and edit it to make it legible (e.g. fix the broken markup, fix your capitalization, use paragraphs, etc.) Furthermore, please provide a proper Minimal, Complete, and Verifiable example (e.g. in the current code sample, what issrc_gray
,detected_edges
,lowThreshold
,ratio
,kernel_size
... ) | Just out of curiosity, why is that code's indentation all over the place? Attention to detail and ability to be consistent are key for a good software engineer.
– Dan Mašek
Nov 10 at 23:12
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to recognize the shape/mark shown in picture 1 highlighted shape (green border)
The scanned object resembles a bridge.
Unfortunately, I don't know how to detect the particular shape.
Picture 2 shows the original RGB picture. 2.Original Image
I edit it with the edge detection "cv::Canny" and the contouring "cv::findContours" (3.Edge detection results).
From this point on I don't know what to do.
I use opencv 3.4.2 and libfreenect2 in c++.
I use the kinect v2 for the recording.
The code section calls the image (3.) and edits it using "findContours". However, only the outer rectangle is displayed. But I would like to display the whole form as in picture (1). Unfortunately I don't have any ideas how to do this.
I would be very happy about help. Feel free to send some code examples.
Thank you
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
imwrite ("Canny.png", dst);
image=imread ("Canny.png");
Mat converted (image.rows, image.cols, CV_8UC1);
Mat dat (image.rows, image.cols, CV_8UC1, Scalar ::all(0));
cvtColor(image, converted, COLOR_BGR2GRAY,1);
dilate(converted, converted, Mat(), Point(-1.5,-1.5));
threshold (converted, converted,25, 255, THRESH_BINARY);
//findContours (converted, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
findContours (converted, contours,hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
// Mat drawing =Mat::zeros (converted.size(), CV_8UC3);
for (int i=0; i<contours.size(); i++)
{
double a= contourArea (contours[i], false);
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i;
bounding_rect=boundingRect (contours[i]);
}
}
Scalar color (255,255,255);
drawContours (dat, contours, largest_contour_index, color, CV_FILLED,8,hierarchy);
rectangle (image, bounding_rect , Scalar (0,255,0),1,8,0);
imshow("dat", image);
imshow ("largestContour", dat);
imwrite("largestContour.png", image);
imwrite("dat.png", dat);
c++ opencv object-detection shapes kinect-v2
I want to recognize the shape/mark shown in picture 1 highlighted shape (green border)
The scanned object resembles a bridge.
Unfortunately, I don't know how to detect the particular shape.
Picture 2 shows the original RGB picture. 2.Original Image
I edit it with the edge detection "cv::Canny" and the contouring "cv::findContours" (3.Edge detection results).
From this point on I don't know what to do.
I use opencv 3.4.2 and libfreenect2 in c++.
I use the kinect v2 for the recording.
The code section calls the image (3.) and edits it using "findContours". However, only the outer rectangle is displayed. But I would like to display the whole form as in picture (1). Unfortunately I don't have any ideas how to do this.
I would be very happy about help. Feel free to send some code examples.
Thank you
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
imwrite ("Canny.png", dst);
image=imread ("Canny.png");
Mat converted (image.rows, image.cols, CV_8UC1);
Mat dat (image.rows, image.cols, CV_8UC1, Scalar ::all(0));
cvtColor(image, converted, COLOR_BGR2GRAY,1);
dilate(converted, converted, Mat(), Point(-1.5,-1.5));
threshold (converted, converted,25, 255, THRESH_BINARY);
//findContours (converted, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
findContours (converted, contours,hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
// Mat drawing =Mat::zeros (converted.size(), CV_8UC3);
for (int i=0; i<contours.size(); i++)
{
double a= contourArea (contours[i], false);
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i;
bounding_rect=boundingRect (contours[i]);
}
}
Scalar color (255,255,255);
drawContours (dat, contours, largest_contour_index, color, CV_FILLED,8,hierarchy);
rectangle (image, bounding_rect , Scalar (0,255,0),1,8,0);
imshow("dat", image);
imshow ("largestContour", dat);
imwrite("largestContour.png", image);
imwrite("dat.png", dat);
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
imwrite ("Canny.png", dst);
image=imread ("Canny.png");
Mat converted (image.rows, image.cols, CV_8UC1);
Mat dat (image.rows, image.cols, CV_8UC1, Scalar ::all(0));
cvtColor(image, converted, COLOR_BGR2GRAY,1);
dilate(converted, converted, Mat(), Point(-1.5,-1.5));
threshold (converted, converted,25, 255, THRESH_BINARY);
//findContours (converted, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
findContours (converted, contours,hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
// Mat drawing =Mat::zeros (converted.size(), CV_8UC3);
for (int i=0; i<contours.size(); i++)
{
double a= contourArea (contours[i], false);
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i;
bounding_rect=boundingRect (contours[i]);
}
}
Scalar color (255,255,255);
drawContours (dat, contours, largest_contour_index, color, CV_FILLED,8,hierarchy);
rectangle (image, bounding_rect , Scalar (0,255,0),1,8,0);
imshow("dat", image);
imshow ("largestContour", dat);
imwrite("largestContour.png", image);
imwrite("dat.png", dat);
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
src.copyTo( dst, detected_edges);
imshow( window_name, dst );
imwrite ("Canny.png", dst);
image=imread ("Canny.png");
Mat converted (image.rows, image.cols, CV_8UC1);
Mat dat (image.rows, image.cols, CV_8UC1, Scalar ::all(0));
cvtColor(image, converted, COLOR_BGR2GRAY,1);
dilate(converted, converted, Mat(), Point(-1.5,-1.5));
threshold (converted, converted,25, 255, THRESH_BINARY);
//findContours (converted, contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE );
findContours (converted, contours,hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
// Mat drawing =Mat::zeros (converted.size(), CV_8UC3);
for (int i=0; i<contours.size(); i++)
{
double a= contourArea (contours[i], false);
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i;
bounding_rect=boundingRect (contours[i]);
}
}
Scalar color (255,255,255);
drawContours (dat, contours, largest_contour_index, color, CV_FILLED,8,hierarchy);
rectangle (image, bounding_rect , Scalar (0,255,0),1,8,0);
imshow("dat", image);
imshow ("largestContour", dat);
imwrite("largestContour.png", image);
imwrite("dat.png", dat);
c++ opencv object-detection shapes kinect-v2
c++ opencv object-detection shapes kinect-v2
edited Nov 11 at 10:37
asked Nov 10 at 16:47
Jule
11
11
Please, take a moment to proof-read your question and edit it to make it legible (e.g. fix the broken markup, fix your capitalization, use paragraphs, etc.) Furthermore, please provide a proper Minimal, Complete, and Verifiable example (e.g. in the current code sample, what issrc_gray
,detected_edges
,lowThreshold
,ratio
,kernel_size
... ) | Just out of curiosity, why is that code's indentation all over the place? Attention to detail and ability to be consistent are key for a good software engineer.
– Dan Mašek
Nov 10 at 23:12
add a comment |
Please, take a moment to proof-read your question and edit it to make it legible (e.g. fix the broken markup, fix your capitalization, use paragraphs, etc.) Furthermore, please provide a proper Minimal, Complete, and Verifiable example (e.g. in the current code sample, what issrc_gray
,detected_edges
,lowThreshold
,ratio
,kernel_size
... ) | Just out of curiosity, why is that code's indentation all over the place? Attention to detail and ability to be consistent are key for a good software engineer.
– Dan Mašek
Nov 10 at 23:12
Please, take a moment to proof-read your question and edit it to make it legible (e.g. fix the broken markup, fix your capitalization, use paragraphs, etc.) Furthermore, please provide a proper Minimal, Complete, and Verifiable example (e.g. in the current code sample, what is
src_gray
, detected_edges
, lowThreshold
, ratio
, kernel_size
... ) | Just out of curiosity, why is that code's indentation all over the place? Attention to detail and ability to be consistent are key for a good software engineer.– Dan Mašek
Nov 10 at 23:12
Please, take a moment to proof-read your question and edit it to make it legible (e.g. fix the broken markup, fix your capitalization, use paragraphs, etc.) Furthermore, please provide a proper Minimal, Complete, and Verifiable example (e.g. in the current code sample, what is
src_gray
, detected_edges
, lowThreshold
, ratio
, kernel_size
... ) | Just out of curiosity, why is that code's indentation all over the place? Attention to detail and ability to be consistent are key for a good software engineer.– Dan Mašek
Nov 10 at 23:12
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241165%2fdetect-a-irregular-shape-with-opencv-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please, take a moment to proof-read your question and edit it to make it legible (e.g. fix the broken markup, fix your capitalization, use paragraphs, etc.) Furthermore, please provide a proper Minimal, Complete, and Verifiable example (e.g. in the current code sample, what is
src_gray
,detected_edges
,lowThreshold
,ratio
,kernel_size
... ) | Just out of curiosity, why is that code's indentation all over the place? Attention to detail and ability to be consistent are key for a good software engineer.– Dan Mašek
Nov 10 at 23:12