Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The error I am facing is that I couldn't use the same images which I have declared earlier as input from the user. How to solve that?? I was coding in Python in Google Colab.

My code is given below and the link to my notebook is also given below

This is the error -

image position numbers   1 	 2 	 3 
			 4 	 5 	 6 
			 7 	 8 	 9
for swapping the images... if you want 3rd image in first position... answer the question... first position => img3
Which image do you want in the first position =>img3
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-e34762103183> in <module>()
      2 print("for swapping the images... if you want 3rd image in first position... answer the question... first position => img3")
      3 a=input("Which image do you want in the first position =>")
----> 4 img13=np.ndarray(a)
      5 cv2_imshow(img13)
      6 b=np.array(input("Which image do you want in the second position =>"))

TypeError: 'str' object cannot be interpreted as an integer


What I have tried:

This is my code

import numpy as np

importing numpy

import cv2 as cv
from google.colab.patches import cv2_imshow

importing cv in colab

img=cv.imread("5.jpg")
cv2_imshow(img)

image of the Louvre museum

img0 = cv.resize(img ,(600,372))#for being able to work with the second image
cv2_imshow(img0)


type(img0)


img1=img0[0:124,0:200]
img2=img0[0:124,200:400]
img3=img0[0:124,400:600]
img4=img0[124:248,0:200]
img5=img0[124:248,200:400]
img6=img0[124:248,400:600]
img7=img0[248:372,0:200]
img8=img0[248:372,200:400]
img9=img0[248:372,400:600]

cv2_imshow(img1)
cv2_imshow(img2)
cv2_imshow(img3)
cv2_imshow(img4)
cv2_imshow(img5)
cv2_imshow(img6)
cv2_imshow(img7)
cv2_imshow(img8)
cv2_imshow(img9)

cutting images in 9 parts

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

cv2_imshow(img10)
cv2_imshow(img11)
cv2_imshow(img12)

making the jumbled image

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")
a=input("Which image do you want in the first position =>")
img13=np.ndarray(a) #error line
cv2_imshow(img13)
b=np.array(input("Which image do you want in the second position =>"))
img14=cv.hconcat([a,b])
cv2_imshow(img14)
c=np.array(input("Which image do you want in the third position =>"))
img15=cv.hconcat([a,b,c])
cv2_imshow(img15)
d=np.array(input("Which image do you want in the fourth position =>"))
img16=cv.hconcat([d])
cv2_imshow(img15)
cv2_imshow(img16)
e=np.array(input("Which image do you want in the fifth position =>"))
img17=cv.hconcat([d,e])
cv2_imshow(img15)
cv2_imshow(img17)
f=np.array(input("Which image do you want in the sixth position =>"))
img18=cv.hconcat([d,e,f])
cv2_imshow(img15)
cv2_imshow(img18)
g=np.array(input("Which image do you want in the seventh position =>"))
img19=cv.hconcat([g])
cv2_imshow(img15)
cv2_imshow(img18)
cv2_imshow(img19)
h=np.array(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=np.array(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)


This is the error block
Posted
Updated 22-Mar-22 21:06pm
v4

1 solution

 
Share this answer
 
Comments
Atharav Jadhav 23-Mar-22 4:14am    
But now it is showing an error like this

image position numbers 1 2 3
4 5 6
7 8 9
for swapping the images... if you want 3rd image in first position... answer the question... first position => img3
Which image do you want in the first position =>img3
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-28-397661390523> in <module>()
1 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")
2 print("for swapping the images... if you want 3rd image in first position... answer the question... first position => img3")
----> 3 a=int(input("Which image do you want in the first position =>"))
4 img13=np.ndarray(a)
5 cv2_imshow(img13)

ValueError: invalid literal for int() with base 10: 'img3'
Atharav Jadhav 23-Mar-22 4:15am    
link to the program

https://colab.research.google.com/drive/1J-ZnvEDRL3lxBYtGeRcWQ2dctkC2yBb9#scrollTo=Trc6KHIYILXE

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900