Image Frame Aspect Ratio

I’m trying to adjust a PNG image frame to autofit around another image. I’m using separate Replicator COMPs, one for frames and one for the images to fill the frames. I’m doing it this way to be able to randomize frames on the images, since there are way fewer frames than there are images.

I’m not sure if this is a good method, but I though maybe using openCV or GLSL to detect the edges of the image, then using that to somehow resize the frames to fit- but I can’t really get it to work. TBF I’m not well-versed in either language.

I tried creating a matte from the frame, then comp that over a black background. That sort of works to mask the area around the frame and not allow the image to show beyond that, but I need to keep transparency around the outside of the frames(so I can layer over a background), so resizing each frame to fit the image seems like it would be the better way. Maybe I’m just not thinking of an easier solution, I could really use some help on this one!

Attached image is a just a crop of the final output. Final output will be about 40 randomized images at any time (thus the replicators).

I’m a little confused about your setup. Are you in control of the placement / rotation of each image separately, or are you trying to detect frames from a source image of a bunch of pictures already randomly rotated/placed? If you’re in control, this should be pretty straightforward, and your topic title seems to suggest you just need to find the aspect ratio ( which is easy, myTop.width / myTop.height), but by your mention of wanting to “detect” the images it sounds like you indeed are working with a pre-composed source/input?

I’m not an expert, but I am pretty certain there are some python or c++ libs/functions that use OpenCV that can get you aspect ratios and analyzed transforms of flat rectangles detected in perspective. You just have to find the right way to get the source image data to that process, then you likely would get a set of transform data that could be applied to replicated geo comps that get rendered to composite over your background.

Perhaps if you have a sample toe that shows what you are trying to do folks could weigh in more.