0

already finding the white corner from discussion Get corners of rectangle from black and white image, but fail ?!
expect to locate like (pic-expect) in link: https://i.stack.imgur.com/40U63.jpg

the .py script locate white edge code

import cv2 as cv
import pprint as pprint

img = cv.imread("/home/joy/桌面/test_11_8/original.png") # read image
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) # make grayscale image

cv.imshow("Our initial image",img) # show our original image 

corners = cv.goodFeaturesToTrack(gray,2000,0.01,5) # find our corners, 2000 is the number of corners we can detect, 5 is the distance between corners 

xylist = [] #put all of our xy coords in here 

for corn in corners: # extract our corners and put them in xylist
    x,y = corn[0]
    xylist.append((x,y))
    x = int(x)
    y = int(y)
    cv.rectangle(img, (x-2,y-2), (x+2,y+2), (100,100,0),-1) # now mark where our corners are on our original image
            
res = [[] for i in range(int(len(xylist)/4))] # generate i nested lists for our rectangles
        
for index, item in enumerate(xylist): # format coordinates as you want them
   res[index % int(len(xylist)/4)].append(item)
        
print("\n"+"found ",int(len(xylist)/4) ,"rectangles\n") # how many rectangles did we have?       
print(res)

cv.imshow("Corners?", img) # show our new image with rectangle corners marked
if cv.waitKey(0)& 0xff ==27:
    cv.destoryAllWindows()
beaker
  • 16,331
  • 3
  • 32
  • 49
  • Why don't you just try thresholding on white. Then get contours. Then get the bounding boxes or the rotated bounding boxes as desired. – fmw42 Nov 08 '22 at 03:17
  • Since each sticker contains a data matrix, one approach would be to find the data matrixes in the image, and use their coordinates to locate the sticker: https://stackoverflow.com/questions/62300127/selecting-the-data-matrix-from-a-image-and-decoding-it Would also give you the text in the data matrix, which may be useful too. – Nick ODell Nov 08 '22 at 04:47

0 Answers0