Loading openCV images

Asked 2 years ago, Updated 2 years ago, 68 views

import cv2

img_color=cv2.imread('aaa.jpeg',cv2.IMREAD_COLOR)
cv2.namedWindow('Color')
cv2.imshow('Color',img_color)
cv2.waitKey(0)
cv2.destroyAllWindows()

I try to import openCV and import the image to declare a variable (img_color), but I keep getting a syntax error.

/Users/suhankim/PycharmProjects/untitled1/venv/bin/python /Users/suhankim/PycharmProjects/cvex/cvex.py
  File "/Users/suhankim/PycharmProjects/cvex/cvex.py", line 4
    img_color=cv2.imread('aaa.jpeg',cv2.IMREAD_COLOR)
             ^
SyntaxError: invalid character in identifier

Process finished with exit code 1

The image you want to import is located below.

No matter how hard I look at it, there's no place for trouble What's the problem?

python opencv

2022-09-20 21:56

2 Answers

a = "img_color=cv2.imread('aaa.jpeg',cv2.IMREAD_COLOR)\
cv2.namedWindow('Color')\
cv2.imshow('Color',img_color)\
cv2.waitKey(0)\
cv2.destroyAllWindows()"
print(a)
result = ''
for i in a:
    result += i+'('+str(ord(i))+')' 
print (result)

result
'''
img_color=cv2.imread('aaa.jpeg',cv2.IMREAD_COLOR)cv2.namedWindow('Color')cv2.imshow('Color',img_color)cv2.waitKey(0)cv2.destroyAllWindows()
i(105)
m(109)g(103)_(95)c(99)o(111)
l(108)o(111)r(114)(65279)=(61)
(65279)c(99)v(118)2(50).(46)
i(105)m(109)r(114)e(101)a(97)
d(100)((40)'(39)a(97)a(97)
a(97).(46)j(106)p(112)e(101)
g(103)'(39),(44)(65279)c(99)
v(118)2(50).(46)I(73)M(77)
R(82)E(69)A(65)D(68)_(95)
C(67)O(79)L(76)O(79)R(82)
)(41)c(99)v(118)2(50).(46)
n(110)a(97)m(109)e(101)d(100)
W(87)i(105)n(110)d(100)o(111)
w(119)((40)'(39)C(67)o(111)
l(108)o(111)r(114)'(39))(41)
c(99)v(118)2(50).(46)i(105)
m(109)s(115)h(104)o(111)w(119)
((40)'(39)C(67)o(111)l(108)
o(111)r(114)'(39),(44)(65279)
i(105)m(109)g(103)_(95)c(99)
o(111)l(108)o(111)r(114))(41)
c(99)v(118)2(50).(46)w(119)
a(97)i(105)t(116)K(75)e(101)
y(121)((40)0(48))(41)c(99)
v(118)2(50).(46)d(100)e(101)
s(115)t(116)r(114)o(111)y(121)
A(65)l(108)l(108)W(87)i(105)
n(110)d(100)o(111)w(119)s(115)
((40))(41)
''

I typed it in the comments, but I don't think it's an accurate answer, so I'm deleting it and replying with more direct help. Next to =, there is a value of ascii decimal 65279 garbage, which seems to indicate an identifier that cannot be verified.

It looks better to rewrite it, not copy and paste.


2022-09-20 21:56

When I copied it and looked at it in the Hexa editor, there were invisible characters.

img_color<BOM>=<BOM>cv2.imread

The characters in <BOM> are 0xef 0xbb 0xbf byte columns with 0xef 0xbf-8 . Usually, when a text file is utf-8 encoded, it is the value that you put at the beginning of a text file, such as a Windows Notepad.

I think you can erase that line neatly and type it back in with the keyboard...

When I copied the source you posted, I found this text everywhere.


2022-09-20 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.