r/computervision • • 2h ago

Help: Project OpenCV Perspective Transform – ROI Alignment Issue

Hi everyone,
I’m working on a machine vision project using OpenCV to detect ICs in a JEDEC tray.

My current process:
-Detect four circular fiducials near the tray corners.
-Use their centres to calculate a perspective transformation.
-Warp the image into a fixed rectangular image.
-Generate ROIs for the tray pockets.

I’m currently facing an alignment issue. After perspective warping, the ROI boxes do not seem to align consistently with the actual tray pockets. Some areas appear well aligned(on row and collum) as example top left pocket and bottom left pocket of the tray, while others have noticeable offsets. I’ve attached two images for comparison.

I’m not sure whether the issue is caused by:
-Inaccurate fiducial centre detection
-Incorrect fiducial reference points
-Perspective transformation
-Residual geometric distortion
-Other factors I may have overlooked

I’d appreciate any suggestions on how to identify the root cause and improve the alignment.
Has anyone experienced a similar issue with machine vision calibration or perspective transformation?
Thank you!

Ps : ive got the screenshot now thankyou guys hahahah

2 Upvotes

7 comments sorted by

1

u/Perse95 2h ago

4 points can correct perspective warping, but if your camera has a nonlinear distortion component due to the lens(es), then 4 points is insufficient to correct for that.

Could you use the fact that the tray pockets are like a dot pattern grid and use that for correcting the distortion? It should be straightforward to detect that there are N rows and M columns and then find circles based on that.

1

u/Grouchy_Signal139 2h ago

Thanks for the suggestion! I hadn’t considered using the pocket grid as an additional reference. That’s an interesting approach.
One question: would you recommend detecting the circular pocket openings and using their centres to estimate the grid, or detecting the pocket boundaries themselves?

1

u/Most-Vehicle-7825 2h ago

What did you try since you asked the last time?

For debugging, you could print a target with the four circles and a dense checkboard pattern. Then you run you algorithm and check if it aligns everything. If not, probably your distortion is not good. This also allows you to check in which direction your error points. In you image, you are better at the left side and worse towards right. Any idea why?

1

u/Grouchy_Signal139 2h ago

Hi bro, last time i want to make new setup, get another light making the illumination uniform, it really help with the detection. It could detect reliably but sometimes, because of the roi alignment not really on the tray pocket, i get not consistent result because it cover less area of the pocket.I haven’t tried a dense checkerboard validation yet. Your suggestion sounds useful because it could help me distinguish whether the remaining error comes from lens distortion or the perspective transformation itself. Will update more later hahahah

1

u/blobules 2h ago

First, check manually that the 4 fiducial points are indeed mapped perfectly. Don't just look at an image, get actual coordinates.

Second, remember that a perspective transformation will only work on planar objects. If the fiducial point are not on the same plane as the board, the remapping will be shifted.

Last, as a previous post mentioned, check for radial distortion. You must remove radial distortion if you hope to obtain straight lines after remapping.

1

u/Grouchy_Signal139 2h ago

Thanks for pointing that out! Regarding your second point, my fiducial markers are actually slightly raised above the tray surface because they are mounted on the jig.
Could this height difference cause the perspective transformation to align the four fiducial points correctly but leave the tray pocket positions slightly shifted? I’m wondering if this could explain why the alignment gets progressively worse towards the right side.
I’ll investigate this further. Appreciate your input!

1

u/blobules 1h ago

Yes, the fiducial points need to be on the same plane as the board.

It is not easy to see the shift between the images. I suggest you subtract one from the other so it is easier to see what is going on.