If I capture a picture from production line, how can I extract the part I want from image
from pic - https://ibb.co/k9wfTT0
to pic - https://ibb.co/BKfMx6w
import cv2
im = cv2.imread('/home/joy/桌面/test_11_2/split_img/original.png')
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
contours, hierarchy = cv2.findContours(gray,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)[-2:]
idx =0
for cnt in contours:
idx += 1
x,y,w,h = cv2.boundingRect(cnt)
roi=im[y:y+h,x:x+w]
cv2.rectangle(im,(x,y),(x+w,y+h),(200,0,0),2)
cv2.imshow('img',im)
cv2.waitKey(0)
my output: https://ibb.co/rkbQy7w
from zxing and zbar tutorial:
https://learnopencv.com/barcode-and-qr-code-scanner-using-zbar-and-opencv/
can detect QR code location, then if I make the locate point larger, might can include the area/sticker I want https://i.stack.imgur.com/4p6hx.jpg
- below discussion might could solve my issue (by extend locate qr code's (x,y) to cover my sticker part) Python - Detect a QR code from an image and crop using OpenCV
(plan B)
To public, can I just directly cut to small pieces, instead of do other process, cause I can just OCR img to text only my desire part
the pic link - https://i.stack.imgur.com/3n3EK.jpg