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












share|improve this question
























  • 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















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












share|improve this question
























  • 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













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












share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ