How to crop the image as wide as possible? [closed]

asked 2018-08-08 11:38:55 -0600

ggrayce gravatar image

I want to be able to crop any image with the smallest bounding box possible. Example: image description

I have the "a" image and want to crop the image with the smallest rectangle that encompasses my image.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-11-29 06:15:37.176825

Comments

well you need to define the bounding box / region of interest as small as possible. If this is not what you want to know - rephrase your question ^^

holger gravatar imageholger ( 2018-08-08 12:34:01 -0600 )edit

Yes, that's what I want. But I do not know how. I have already found this boungingBox function but I do not know how to implement it in a code. I'm new to Opencv and C ++. Could you show me how it would be done?

ggrayce gravatar imageggrayce ( 2018-08-08 12:41:23 -0600 )edit

Can you post the critical code where you get the bounding box? Also its good to give context - what methods calls are you using for bbox detection etc. Are you using contours?

If you mark the bounding box with rectangle and then use imshow - is the result sufficient? If yes it only about extracting - if not - you need to work on the detection,

holger gravatar imageholger ( 2018-08-08 12:50:23 -0600 )edit

Yes, I'm using outlines. What I thought and was trying to do was: 1)I open the image. 2)I use the "canny" function to get the outlines. 3)I draw the contours with "drawcontours".

From there I would use the boundBox to find the minimum rectangle. But I saw that I would have to turn it to get this.

I saw this in:link text In the 7b step.

But in example, he use points, but i have contours.. i don't now how to do.

I have this example too: link text

But he have an circle and when i try cut this parte of code(circle) i don't now what to do.

ggrayce gravatar imageggrayce ( 2018-08-08 13:02:55 -0600 )edit

link text

the exemple of the step 7b.

ggrayce gravatar imageggrayce ( 2018-08-08 13:09:19 -0600 )edit

Hmm i dont get your problem - i suggest: Study once again this examplehttps://docs.opencv.org/2.4/doc/tutor...

In the code you see the following line:

//this is using improc method boundingRect to return a CvRect for a contour poly
boundRect[i] = boundingRect( Mat(contours_poly[i]) );

And later

rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );

Which will draw a rectangle - but you can also these cooridates to extract the region you want to extract. Like here https://stackoverflow.com/questions/8...

Btw the link i copied from you is from opencv 2.4 and we are in 2018 :-)

holger gravatar imageholger ( 2018-08-08 13:19:31 -0600 )edit