How to place one rectangle inside another one without intersections?
My JavaFX applications do the follow: opens background image, opens foreground image and foreground image should be placed inside background "randomly" in such way that foreground image should not intersect contour of background image.
Let me show example, where coordinates of foreground image are hardcoded:
So I did the follow: Using snippet from this question I combine background image and foreground image into one.
After this I tried to find contour of this combined image using code from this article. And it looks like OpenCV finds contours of background image successfully.
But I should place foreground image inside background image, adding some random factor in order to foreground can be inside contour in any place and with any rotation factor, but not intersect contour.
If this question or approach are incorrect, sorry, I'm newbie in OpenCV. This code
Imgproc.findContours(gray, contours, new Mat(),
Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
returns ArrayList in contours of such objects
Mat [ 91*1*CV_32SC2, isCont=true, isSubmat=false, nativeObj=0x1cbdcce0, dataAddr=0x1cac3800 ]
and I have no idea how to use it.