I want to select the region where the Data Matrix is placed.
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread('C:\\Users\\MyAccount\\Desktop\\datamatrix.png')
dmc = img1[300:588, 1225:1512]
plt.imshow(dmc)
plt.show()
I only receive a slim white area, but not a single region of this matrix. The ROI-Formular is [y:y+h, x:x+w], but it is not working.
The image has the size 1240 x 626.
The matrix has the attributes: left=938, top=323, width=287, height=288.
The coordinates you specify in your code don't correspond to what you describe.
Change them to:
dmc = img1[323:611, 938:1225]
If you like to have a relative formula:
import cv2
left=938
top=323
width=287
height=288
img = cv2.imread('temp.png', 0)
imgh, imgw = img.shape[:2]
# compute starting position of top
img = img[(imgh/2-height)/2:(imgh/2-height)/2+height, left:left+width]
cv2.imshow("result", img)
cv2.waitKey()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.