Finding a rectangle in an image
📁 python
Task: Find a hard drive in a photo, determine its angle and contours
Problem: It is not always possible to find the correct contour of the disk.
In the code, I make the images gray, blur them, find the difference between them and determine the contours, but the solution is not accurate. I would like your help.
firstFrame = cv2.imread(bg_im) # Background image without disk
frame_img = cv2.imread(frame) # Image with disk
gray = cv2.cvtColor(frame_img, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
firstFrame = cv2.cvtColor(firstFrame, cv2.COLOR_BGR2GRAY)
firstFrame = cv2.GaussianBlur(firstFrame, (21, 21), 0) As soon as it comes to applying blur with a large kernel size, unfortunately, an irreversible deformation of the object of interest occurs. The object seems to be outlined by contours, but its size, shape (and sometimes position) may significantly differ from the original. Needless to say, morphological operations (erosion, dilation) applied on top only exacerbate the problem.
In the situation with the presented images, complexity also arises from the fact that the conveyor belt has quite noticeable traces of production use. These are scratches, stains, and other similar elements that have different positions on the background image and the image with the object of interest, and generally differ significantly in detail. This point becomes critical when...
Log in to leave an answer