Cartoonify_reality icon indicating copy to clipboard operation
Cartoonify_reality copied to clipboard

ModuleNotFoundError: No module named 'caartoonize'

Open calvin886 opened this issue 3 years ago • 17 comments

when i try to run: python vid.py. it shows error :"ModuleNotFoundError: No module named 'caartoonize'"

calvin886 avatar Oct 12 '20 10:10 calvin886

when i try to run: python vid.py. it shows error :"ModuleNotFoundError: No module named 'caartoonize'"

There is a spelling mistake there. Change the import from caartoonize to cartoonize, it will work.

Shaashwat05 avatar Oct 12 '20 10:10 Shaashwat05

Thanks a lot, it works after I change the word.

But, when i try to run: python vid.py, it shows me an error:

(cartoon) shideMacBook-Pro-4:Cartoonify_reality-master shi$ python vid.py Traceback (most recent call last): File "vid.py", line 3, in <module> from cartoonize import caart File "/Users/shi/Desktop/Cartoonify_reality-master/cartoonize.py", line 111, in <module> output=caart(cv2.imread("original.jpg")) File "/Users/shi/Desktop/Cartoonify_reality-master/cartoonize.py", line 102, in caart contours,_=cv2.findContours(edge,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) ValueError: too many values to unpack (expected 2)

I seems like missing some values in either imread() or findContours() method. Have you seen this error before?

calvin886 avatar Oct 12 '20 11:10 calvin886

Thanks a lot, it works after I change the word.

But, when i try to run: python vid.py, it shows me an error:

(cartoon) shideMacBook-Pro-4:Cartoonify_reality-master shi$ python vid.py Traceback (most recent call last): File "vid.py", line 3, in <module> from cartoonize import caart File "/Users/shi/Desktop/Cartoonify_reality-master/cartoonize.py", line 111, in <module> output=caart(cv2.imread("original.jpg")) File "/Users/shi/Desktop/Cartoonify_reality-master/cartoonize.py", line 102, in caart contours,_=cv2.findContours(edge,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) ValueError: too many values to unpack (expected 2)

I seems like missing some values in either imread() or findContours() method. Have you seen this error before?

In cartoonize.py, comment out the lines outside the caart function(lines 111 and so) since they are used for images to call the function. These lines may be interfering with the actual function for videos.

Also, I tried running the same code and there seem to be no other errors.

Shaashwat05 avatar Oct 12 '20 11:10 Shaashwat05

Thanks for your patience, when i comment out line 111 and line 112 in cartoonize.py, the first error solved. however, there is still a error cartoon) shideMacBook-Pro-4:Cartoonify_reality-master shi$ python vid.py Traceback (most recent call last): File "vid.py", line 14, in <module> img=caart(img) File "/Users/shi/Desktop/Cartoonify_reality-master/cartoonize.py", line 102, in caart contours,_=cv2.findContours(edge,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) ValueError: too many values to unpack (expected 2)

It seems like, the findContours() function return more than two items, so the error happened. Do you have any idea about this error?

calvin886 avatar Oct 12 '20 14:10 calvin886

Thanks for your patience, when i comment out line 111 and line 112 in cartoonize.py, the first error solved. however, there is still a error cartoon) shideMacBook-Pro-4:Cartoonify_reality-master shi$ python vid.py Traceback (most recent call last): File "vid.py", line 14, in <module> img=caart(img) File "/Users/shi/Desktop/Cartoonify_reality-master/cartoonize.py", line 102, in caart contours,_=cv2.findContours(edge,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) ValueError: too many values to unpack (expected 2)

It seems like, the findContours() function return more than two items, so the error happened. Do you have any idea about this error?

Its no problem, thank you for the doubts.

So I checked the OpenCV documentation and there seem to be 3 values that the findContours() function returns. The issue is that I ran the same code today and there was no error. Maybe it is because of version changes.

Try using 3 values as input to the function, with the middle value as contours. This should solve the problem

Shaashwat05 avatar Oct 12 '20 18:10 Shaashwat05

Since the error says that the output values unpacked were 0, the image is not loaded correctly. It mostly means that your path to the image may be incorrect

On Sun, Dec 27, 2020 at 10:47 PM maitra [email protected] wrote:

I have a different, perhaps related error:

Traceback (most recent call last): File "/home/personal/cartoons/Cartoonify_reality-master/cartoonize.py", line 111, in output=caart(cv2.imread("original.jpg")) File "/home/personal/cartoons/Cartoonify_reality-master/cartoonize.py", line 72, in caart x,y,c=output.shape ValueError: not enough values to unpack (expected 3, got 0)

How do I get around this error? Thanks!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Shaashwat05/Cartoonify_reality/issues/1#issuecomment-751493148, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDK6QZ3E5HKNJFMHWP2733SW5T2JANCNFSM4SMTXN7Q .

Shaashwat05 avatar Dec 27 '20 17:12 Shaashwat05

yes, you may consider fixing the line that is supposed to be uncommented. By default, the filename should be original2.jpg. But thanks for the code.

maitra avatar Dec 27 '20 17:12 maitra

yes, you may consider fixing the line that is supposed to be uncommented. By default, the filename should be original2.jpg. But thanks for the code.

Happy to help

Shaashwat05 avatar Dec 27 '20 17:12 Shaashwat05

Btw, the k-means clustering: does it cluster by individual channel? What is K here?

maitra avatar Dec 27 '20 18:12 maitra

Btw, the k-means clustering: does it cluster by individual channel? What is K here?

It clusters the channels individually. So normally, an image is 8-bit right. In this, we try to cluster the 8-bits into 4-5 bits to reduce the number of colors. K is the number of bits.

Shaashwat05 avatar Dec 27 '20 18:12 Shaashwat05

Btw, the k-means clustering: does it cluster by individual channel? What is K here?

It clusters the channels individually. So normally, an image is 8-bit right. In this, we try to cluster the 8-bits into 4-5 bits to reduce the number of colors. K is the number of bits.

I see, thanks! I wonder if we can distort the cartoon. Perhaps adding random noise to the contours might do it. Btw, separately, askopenfile from tkinter can stop the hardcoding of the input.

maitra avatar Dec 27 '20 18:12 maitra

def select_input() -> None:
    file = askopenfile(title='Please select one (any) frame from your set of ima
ges.',
                       filetypes=[('Image Files', ['.jpeg', '.jpg', '.png', '.gi
f',
                                                   '.tiff', '.tif', '.bmp'])])
    if file != None:
        return(file.name)
    
img_path=select_input()

output=caart(cv2.imread(img_path))

Hereis how you can do this. Should probably fix the output too, just add cartoon.jpg, after the filename (without extension).

maitra avatar Dec 27 '20 19:12 maitra

Btw, the k-means clustering: does it cluster by individual channel? What is K here?

It clusters the channels individually. So normally, an image is 8-bit right. In this, we try to cluster the 8-bits into 4-5 bits to reduce the number of colors. K is the number of bits.

I see, thanks! I wonder if we can distort the cartoon. Perhaps adding random noise to the contours might do it. Btw, separately, askopenfile from tkinter can stop the hardcoding of the input.

How would distortion help??

Shaashwat05 avatar Dec 27 '20 19:12 Shaashwat05

I see, thanks! I wonder if we can distort the cartoon. Perhaps adding random noise to the contours might do it. Btw, separately, askopenfile from tkinter can stop the hardcoding of the input.

How would distortion help??

Distortion would make the image into a true cartoon. Right now, it really makes outlines of the images and that is pretty much it. Right?

maitra avatar Dec 27 '20 19:12 maitra

I see, thanks! I wonder if we can distort the cartoon. Perhaps adding random noise to the contours might do it. Btw, separately, askopenfile from tkinter can stop the hardcoding of the input.

How would distortion help??

Distortion would make the image into a true cartoon. Right now, it really makes outlines of the images and that is pretty much it. Right?

As of now, it reduces the bit size of the image and utilizes other OpenCV filters for contours and edges. I haven't thought of it by using distortion, but you can try and see for yourself.

Shaashwat05 avatar Dec 28 '20 07:12 Shaashwat05

Distortion would make the image into a true cartoon. Right now, it really makes outlines of the images and that is pretty much it. Right?

As of now, it reduces the bit size of the image and utilizes other OpenCV filters for contours and edges. I haven't thought of it by using distortion, but you can try and see for yourself.

Yes, indeed. It will require more work than available routines. There are at least two ways of going about it. Perhaps reduce the widths of the contours randomly, and create an optical illusion. Another, more correct approach spatially distort the contours.

maitra avatar Dec 28 '20 13:12 maitra

Distortion would make the image into a true cartoon. Right now, it really makes outlines of the images and that is pretty much it. Right?

As of now, it reduces the bit size of the image and utilizes other OpenCV filters for contours and edges. I haven't thought of it by using distortion, but you can try and see for yourself.

Yes, indeed. It will require more work than available routines. There are at least two ways of going about it. Perhaps reduce the widths of the contours randomly, and create an optical illusion. Another, more correct approach spatially distort the contours.

That is a nice idea indeed

Shaashwat05 avatar Dec 29 '20 08:12 Shaashwat05