OpenCV findcontour矩形创建

2024-04-25 19:41:41 发布

您现在位置:Python中文网/ 问答频道 /正文

x,y,w,h = cv2.boundingRect(ctr)
leng = int(h*.9)
pt1 = int(y + h // 2 - leng // 2)
pt2 = int(x + w // 2 - leng // 2)
roi = im_th[pt1-int(leng*0.6) : pt1+ int(leng*1.2) , pt2: pt2+leng]
cv2.imwrite("C:\\Users\\kumar\\Desktop\\final year\\test_image\\"+str(idx)+".jpg",roi)
cv2.rectangle(im,(x,y),(x+w,y+h),(0,0,0),3)
roi = roi/255
# Resize the image
roi = cv2.resize(roi, (28, 28), interpolation=cv2.INTER_AREA)
roi=roi*255
cv2.imwrite("C:\\Users\\kumar\\Desktop\\final year\\test_image\\after_resize_"+str(idx)+".jpg",roi)
cv2.waitKey(0) 

当使用这段代码从图像中截取字母时,例如m和u会产生错误

u comes out like this


Tags: testimagecv2yearusersfinalintdesktop