I'm working on a project using PythoN(3.7) and OpenCV in which I have to detect the QR code from an Image/LiveStream and then I need to take the detected QR code as a separate image and this QR code hold the size of this QR code image, so I need to take it out as a seprate image and compare it's size with the decoded size of this QR code Image.
Update:
Here's what I have: I have a document image with a QR code placed on it.Actually, this QR code will have the following information:
- 4 variables (top, right, bottom, left)
- The image size of QR code (for example 10px mean the QR code image is 10x10px)
Here's what I want to achieve:
- I want to detect the QR code and decode (when I decode I will get it's image size)
- Then I have to save the QR code detection (highlighted area) as a separate cropped image.
- Finally, I need to compare the cropped image size with the QR code size (which I get after decoding)
Here's an example Input & Output Image:
I'm done with the QR code detection but how can I capture this particular area as a seprate image and compare it's size with another size which will be inside this QR code?
Here's what I have done so far:
import cv2
# read the image
image = cv2.imread('/Users/abdul/PycharmProjects/QScanner/images/second.jpg')
qrCodeDetector = cv2.QRCodeDetector()
decodedText, points, _ = qrCodeDetector.detectAndDecode(image)
qr_data = decodedText.split(',')
qr_size = qr_data[0]
top = qr_data[1]
right = qr_data[2]
bottom = qr_data[3]
left = qr_data[4]
print(f'Size: {qr_size}' + str(qr_data[5]))
print(f'Top: {top}')
print(f'Right: {right}')
print(f'Bottom: {bottom}')
print(f'Left: {left}')
if points is not None:
pts = len(points)
print(pts)
for i in range(pts):
nextPointIndex = (i+1) % pts
cv2.line(image, tuple(points[i][0]), tuple(points[nextPointIndex][0]), (255,0,0), 5)
print(points[i][0])
print(decodedText)
cv2.imshow("Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print("QR code not detected")