I wanted to make a game where I cut a picture in 9 parts in Google Colab and then Jumbled them. The user would then assemble them in perfect sequence

Viewed 65

The error which I am facing is that When the user gives the wrong input, it is taking so much time to load. I mean I haven't even seen the next line load till now. So I was asking how to solve this delay issue. I would like to mention that when the user gives correct input, the code runs very smoothly.

My code is mentioned below.

So can anyone please answer why my code is wrong?

I am really a beginner at coding. So please excuse my lack of efficiency and methodology

MY CODE

import numpy as np
import cv2 as cv
from google.colab.patches import cv2_imshow
from google.colab import files
img=cv.imread("25.jpg")
cv2_imshow(img)  #an image of Louver Museum
img0 = cv.resize(img ,(600,372))#for being able to work with the second image
cv2_imshow(img0)
img1=img0[0:124,0:200]
cv.imwrite('img7.jpg',img1)
img2=img0[0:124,200:400]
cv.imwrite('img4.jpg',img2)
img3=img0[0:124,400:600]
cv.imwrite('img2.jpg',img3)
img4=img0[124:248,0:200]
cv.imwrite('img9.jpg',img4)
img5=img0[124:248,200:400]
cv.imwrite('img1.jpg',img5)
img6=img0[124:248,400:600]
cv.imwrite('img6.jpg',img6)
img7=img0[248:372,0:200]
cv.imwrite('img5.jpg',img7)
img8=img0[248:372,200:400]
cv.imwrite('img3.jpg',img8)
img9=img0[248:372,400:600]
cv.imwrite('img8.jpg',img9)

cv2_imshow(img1) #image cut in 9 pieces
cv2_imshow(img2)
cv2_imshow(img3)
cv2_imshow(img4)
cv2_imshow(img5)
cv2_imshow(img6)
cv2_imshow(img7)
cv2_imshow(img8)
cv2_imshow(img9)

I know I should have used loops here, but I am really a beginner in Python. Hence decided to write the whole thing

img10=cv.hconcat([img7, img4, img2])  #making the jumbled image
img11=cv.hconcat([img9, img1, img6])
img12=cv.hconcat([img5, img3, img8])

cv2_imshow(img10)
cv2_imshow(img11)
cv2_imshow(img12)
print("image position numbers   1 \t 2 \t 3 \n\t\t\t 4 \t 5 \t 6 \n\t\t\t 7 \t 8 \t 9")
print("for swapping the images... if you want 3rd image in first position... answer the question... first position => img3.jpg")
a=cv.imread(input('Which image do you want in the first position =>'))
img13=cv.hconcat([a])
cv2_imshow(img13)
b=cv.imread(input('Which image do you want in the second position =>')) #at this line the code stops running
img14=cv.hconcat([a,b])
cv2_imshow(img14)
c=cv.imread(input('Which image do you want in the third position =>'))
img15=cv.hconcat([a,b,c])
cv2_imshow(img15)
d=cv.imread(input('Which image do you want in the fourth position =>'))
img16=cv.hconcat([d])
cv2_imshow(img15)
cv2_imshow(img16)
e=cv.imread(input('Which image do you want in the fifth position =>'))
img17=cv.hconcat([d,e])
cv2_imshow(img15)
cv2_imshow(img17)
f=cv.imread(input('Which image do you want in the sixth position =>'))
img18=cv.hconcat([d,e,f])
cv2_imshow(img15)
cv2_imshow(img18)
g=cv.imread(input('Which image do you want in the seventh position =>'))
img19=cv.hconcat([g])
cv2_imshow(img15)
cv2_imshow(img18)
cv2_imshow(img19)
h=cv.imread(input('Which image do you want in the eight position =>'))
img20=cv.hconcat([g,h])
cv2_imshow(img15)
cv2_imshow(img18)
cv2_imshow(img20)
i=cv.imread(input('Which image do you want in the ninth position =>'))
img21=cv.hconcat([g,h,i])
cv2_imshow(img15)
cv2_imshow(img18)
cv2_imshow(img21)
0 Answers
Related