Объясни что делает данный кусок кода clone = image.copy() imgFloat =…
- User
Объясни что делает данный кусок кода clone = image.copy() imgFloat = clone.astype(np.float64) / 255. kChannel = 1 - np.max(imgFloat, axis=2) kChannel = (255 * kChannel).astype(np.uint8) _, thresh = cv2.threshold(kChannel, 190, 255, cv2.THRESH_BINARY)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5)) close = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=2) cnts = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = cnts[0] if len(cnts) == 2 else cnts[1] for c in cnts: peri = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.04 * peri, True) x,y,w,h = cv2.boundingRect(approx) x,y,w,h = floor(x), floor(y), ceil(w), ceil(h) area = cv2.contourArea(c) ar = w / float(h) if len(approx) == 4 and area > 9000 and ar < 1.3: cropped_image = image[y-5:y+h+5, x-5:x+w+5] height, width, cannal = cropped_image.shape if height==0 or width==0: continue - Assistant
Этот кусок кода выполняет обработку изображения и, вероятно, нацелен на поиск и обрезку некоторых областей, соответствующих определённым критериям. Вот шаги, которые выполняет код:
- User
данный код ищет квадрат или прямоугольник который содержит QR код Улучши данный код
- Assistant
- User
QR код может быть немного прямоугольником, исправь
- Assistant
- User
Улучши код import cv2 import numpy as np import uuid from math import floor, ceil
image = cv2.imread(filename='15-9_2_03052023100145_004.jpg')
clone = image.copy() imgFloat = clone.astype(np.float64) / 255. kChannel = 1 - np.max(imgFloat, axis=2) kChannel = (255 * kChannel).astype(np.uint8) _, thresh = cv2.threshold(kChannel, 190, 255, cv2.THRESH_BINARY)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5,5)) close = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=2)
cnts = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = cnts[0] if len(cnts) == 2 else cnts[1] for c in cnts: peri = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.04 * peri, True) x,y,w,h = cv2.boundingRect(approx) x,y,w,h = floor(x), floor(y), ceil(w), ceil(h) area = cv2.contourArea(c) ar = w / float(h) if len(approx) == 4 and area > 9000 and ar < 1.3: cropped_image = image[y-5:y+h+5, x-5:x+w+5]
height, width, cannal = cropped_image.shape if height==0 or width==0: continue cv2.imwrite('QRCODE2_'+str(uuid.uuid4())+".png", cropped_image) - Assistant
- User
не нужно распознавания QR кода в коде, только сохранение
- Assistant
- User
Данный код не находит то что надо по сравнению с кодом который я привел, исправь
- Assistant
- User
Как добавить cropped_image белый бордюр из 5 пикселей
- Assistant