简体   繁体   中英

opencv java - detect all the rectangles and fill them with an image

I am currently working on a solution for an automatic image edit.

And I have used Canny Edge Detection and Closing.

But What I ultimately want to accomplish is to find all the rectangles from blueprint and fill them with an image what I have.

I want to know the process that I need to take, not the exact code or solution!

Please suggest me what steps should I take to accomplish it, thx.

Image that has the rectangles

Image that needs to go into all the rectangles

what i have done so far

2018-02-12 EDITTED(clean rectangle detected)

// I have done finding the rectangles and drawing lines over them, but the result is not really reliable than I expected(it draws line on rectangles those are not a parking space), and I do not know how to put an image on those rectangle instead of drawing line on them. please help me out!

PS : Only in JAVA please !

In your case, you don't need Canny. Your image is really clean and edges are really visible already. A simple Threshold, will work better.

For rectangle detection take a look at this example (included with opencv) that uses findcontours and checks the angles: https://github.com/opencv/opencv/blob/master/samples/cpp/squares.cpp

In your case, you can skip the Canny step because you don't have gradients. You may need to modify the filtering, like side dimensions for your case.

Once the rectangles look good, you just need to copy your image in the location. If rectangles are rotated, you will have to rotate your image as well.

EDIT: To copy the small image onto the big image you can do the following

Mat submatImg = bigImage.submat(new Rect(x, y, smallImage.width(), smallImage.height());
smallImage.copyTo(submatImg);

If you need to do resizing and rotations, take a look at geometric transformations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM