0

so, I have this code in which I'm comparing five images (don't mind that part of the code, I just wanted to give you guys some context) through IF statements but I'm getting an indentation error inside them and I just couldn't solve it. I just can't see my mistake, I need a second opinion :(

import cv2

width=50
height=50
dimension = (width,height)

img1 = cv2.cv2.imread('D:/Scripts/img/CAPTCHA/Imagen_0.png',cv2.cv2.IMREAD_GRAYSCALE)
img2 = cv2.cv2.imread('D:/Scripts/img/CAPTCHA/Imagen_1.png',cv2.cv2.IMREAD_GRAYSCALE)
img3 = cv2.cv2.imread('D:/Scripts/img/CAPTCHA/Imagen_2.png',cv2.cv2.IMREAD_GRAYSCALE)
img4 = cv2.cv2.imread('D:/Scripts/img/CAPTCHA/Imagen_3.png',cv2.cv2.IMREAD_GRAYSCALE)
img5 = cv2.cv2.imread('D:/Scripts/img/CAPTCHA/Imagen_4.png',cv2.cv2.IMREAD_GRAYSCALE)

img1 = cv2.cv2.resize(img1,dimension,interpolation=cv2.cv2.INTER_AREA)
img2 = cv2.cv2.resize(img2,dimension,interpolation=cv2.cv2.INTER_AREA)
img3 = cv2.cv2.resize(img3,dimension,interpolation=cv2.cv2.INTER_AREA)
img4 = cv2.cv2.resize(img4,dimension,interpolation=cv2.cv2.INTER_AREA)
img5 = cv2.cv2.resize(img5,dimension,interpolation=cv2.cv2.INTER_AREA)


if cv2.cv2.countNonZero(img1[0]) != cv2.cv2.countNonZero(img2[0]):
    if cv2.cv2.countNonZero(img1[0]) == cv2.cv2.countNonZero(img3[0]):
        #search image 2
    else:
        #search image 1
else:
    if cv2.cv2.countNonZero(img1[0]) != cv2.cv2.countNonZero(img3[0]):
        if cv2.cv2.countNonZero(img1[0]) == cv2.cv2.countNonZero(img4[0]):
            #search image 3
        else:
            #no image found
    else:
        if cv2.cv2.countNonZero(img1[0]) != cv2.cv2.countNonZero(img4[0]):
            if cv2.cv2.countNonZero(img1[0]) == cv2.cv2.countNonZero(img5[0]):
                #search image 4
        else:
                #search image 5


Please help me with the IF statements structure, don't worry about the rest of the code :( I just need to solve the indentation problem.

Phillyclause89
  • 674
  • 4
  • 12
  • I use #this as a way to leave comments in my code :( – Sebastián Muñoz Alvial Apr 12 '20 at 03:17
  • 2
    Please reduce this into the expected [MRE](https://stackoverflow.com/help/minimal-reproducible-example). You've posted 30-plus lines of code for a 4-line problem, and you failed to include the error message. – Prune Apr 12 '20 at 04:07

1 Answers1

0

You need to have some sort of valid code inside of each of your conditionals. Use pass as a placeholder until you are ready to write some code there:

if cv2.cv2.countNonZero(img1[0]) != cv2.cv2.countNonZero(img2[0]):
    if cv2.cv2.countNonZero(img1[0]) == cv2.cv2.countNonZero(img3[0]):
        #search image 2
        pass
    else:
        #search image 1
        pass
else:
    if cv2.cv2.countNonZero(img1[0]) != cv2.cv2.countNonZero(img3[0]):
        if cv2.cv2.countNonZero(img1[0]) == cv2.cv2.countNonZero(img4[0]):
            #search image 3
            pass
        else:
            #no image found
            pass
    else:
        if cv2.cv2.countNonZero(img1[0]) != cv2.cv2.countNonZero(img4[0]):
            if cv2.cv2.countNonZero(img1[0]) == cv2.cv2.countNonZero(img5[0]):
                #search image 4
                pass
        else:
            pass
                #search image 5

Some Extra Reading on pass:

https://www.programiz.com/python-programming/pass-statement

https://www.educative.io/edpresso/what-is-pass-statement-in-python

https://www.w3schools.com/python/ref_keyword_pass.asp

How to use the pass statement?

https://www.geeksforgeeks.org/break-continue-and-pass-in-python/

Phillyclause89
  • 674
  • 4
  • 12