This is the error message:

%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "<string>", line 6
image = cv2.imread(“C:\Users\Audun Nilsen\Pictures\pica.webp”)
^
SyntaxError: invalid character in identifier

This is the code:

import cv2 # OpenCV for image processing

image = cv2.imread(“C:\Users\Audun Nilsen\Pictures\pica.webp”)

Assuming this is python you have to ensure the backslashes are not read as escape characters. Try

image = cv2.imread(r'C:\Users\Audun Nilsen\Pictures\pica.webp')

Using r' in front of a string indicates a raw string and the backslashes will not be interpreted as special unless the backslash is the final character in the string. You could also use

image = cv2.imread(C:\\Users\\Audun Nilsen\\Pictures\\pica.webp')

but I prefer the raw string format.

Thanks. That sorted it.

Now, I have a new problem..

I tried the two variations of quotation marks, without the backslash, and got this:

%Run 'open cv - tot.py'
Traceback (most recent call last):
File "C:\Users\Audun Nilsen\open cv - tot.py", line 8
image = cv2.imread("C:\Users\Audun Nilsen\Pictures\417507225_372771342183154_3253415116081493518_n.jpg")

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

Then I did the r before, and I got this:

%Run 'open cv - tot.py'
Traceback (most recent call last):
File "C:\Users\Audun Nilsen\open cv - tot.py", line 1, in <module>
import cv2 # OpenCV for image processing
ModuleNotFoundError: No module named 'cv2'

I double-checked to see if I had installed it, and ... it was fine.

This is the guide I´m trying to get through:

https://finnstats.com/2024/01/17/python-for-image-based-data-mining/

Sorry for the weird formatting..

What happens if you open a python shell and just type "import cv2"? As I said in your other thread, the problem might be with python 3.12. It imports ok under 3.10.

I tried that using Thonny, and I´m getting the same result.

I tried the same in the "CMD" that opens when I press Python 3.12, and what happened was, it just said nothing and went back to an empty "line", or whatever. I suppose that´s a good sign? It says syntax error a lot on there too.

What sort of programs do you use for this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.