0

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:

Input: enter image description here

Output: enter image description here

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")
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
  • Your first sentence is way too long to understand! Can you split it into 2-3 shorter ones please? Also, the image would be useful. Thank you. – Mark Setchell Feb 21 '20 at 16:21
  • @MarkSetchell I have added an update, hope it will be much clear now. – Abdul Rehman Feb 21 '20 at 16:30
  • 1
    Still not very clear! You have a QR code on a document we can't see and that QR code tells you how big the QR code is? So you need to find the QR code and read the QR code to work out how big the QR code is? Sorry... I don't get it. It sounds impossible... you need to look and see what's behind a closed door so you can tell what's there without opening it? Please just show the image and what is encoded in it. – Mark Setchell Feb 21 '20 at 19:06
  • Please add a sample input image and possible output image so we can experiment on :) – nathancy Feb 21 '20 at 21:37
  • @MarkSetchell I have added an example input & output image, take a look, please! – Abdul Rehman Feb 22 '20 at 11:56
  • For anyone who is wondering... the QR code contains the following information *"6.14,40,30,40,40,px"* I am guessing that is probably germane to the question but I don't know why/how. I make that 5 pieces of information rather than 4 and I fail to see how that can be "top, right, bottom, left" because if so, it means something is 0 pixels tall and 10 pixels wide. – Mark Setchell Feb 22 '20 at 22:05
  • @MarkSetchell take a look at this question: https://stackoverflow.com/q/60359398/7644562 – Abdul Rehman Feb 23 '20 at 05:16

0 Answers0