Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

OPENCV Matrix double region extract

Status
Not open for further replies.

Ilia Gildin

Junior Member level 3
Joined
Sep 27, 2014
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
184
Hello
I have a huge code that doesn't really matter but I have my ROI of B2(boundRect1) but if its larger then 36 pixels in length or height I have to crop it (resize does not help me as it is downgrade quality) when I try to "crop" this image I get an error or black image or image on the original size the already tried ways are:
B2(boundRect1)(Rect(round((boundRect1.width -36) / 2), round((boundRect1.height -36) / 2), round((boundRect1.width -36) / 2) + 36, round((boundRect1.height -36) / 2) + 36)
or saving the B2(boundRect1) to temp matrix and temp(Rect(round((boundRect1.width -36) / 2), round((boundRect1.height -36) / 2), round((boundRect1.width -36) / 2) + 36, round((boundRect1.height -36) / 2) + 36)
or using the Point center = (boundRect1.br() + boundRect1.tl()) * 0.5; to find the center point of the original rectangle and then using

Mat temp1 = Mat::zeros(Size(boundRect1.width,boundRect1.height), CV_8UC3);
for (int i1 = center.x - 18; i1 < center.x + 18; i1++)
{
for(int j1 = 0; j1 < boundRect1.height; j1++)
{
temp1.at<int>(i1,j1) = 1;
}
}

Mat bwCrop1 = Mat::zeros(Size(36,36),CV_8UC3);
bitwise_and(temp1, temp, bwCrop1);
where temp is the original B2(boundRect1) matrix
but it still wont work

thanks in advanced
 

From your code it is not easy to see what is actually happening, which if correctly understood, is including in the ROI a piece of an image not belonging to the complete image. Instead of posting part of the code, I'd recommend you take a time to draw a draft with an illustration of what you want and what's going on.
 

Well I'll try to make it schematically (sorry for not having arrows here)

1. Find the contours of image using cascade of Canny + Watershed (WORKS FINE)

2. Extract the object contour using boundingRect with Canny-Watershed contours on the original image (WORKS FANTASTICLLY)

3. If the Extracted contour is bigger then 36 crop it back to 36 (Start from the center and take pixels in length and height until you will reach 36 stop and show me the resulted image)
How should I make number 3 to work (already tried as explained before Rect on the cropped image of step 2, boundingRect on cropped image of step 2, take zero matrix size of step 2 add '1' to the middle of it and applying and with the matrix of step 2)
All this attempts retrieved me the same matrix of step 2 or zero matrix size of step 2.
Is there anything that can be done?
Thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top