[cv2.error: (-215:Assertion failed) _src.empty() in function 'cvtColor' and python path stitching problem]

cv2.error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' and python path stitching problem

  • When using cv2, the following error occurs:

cv2.error:error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

After searching around, I found that it was because "the picture was not sent", that is to say, there is a problem with the picture path in the script. At this time, you need to check the picture path you entered.
insert image description here

  • python path splicing

My problem is that when doing path combination/splicing, an error occurred, and then I reviewed os.path.join()this function again.

import os

Path1 = './a'
Path2 = 'b'
Path3 = 'c'

Path_1 = Path1 + Path2 + Path3
Path_2 = os.path.join(Path1,Path2,Path3)
print ('Path_1:',Path_1)
print ('Path_2:',Path_2)

The output results are as follows:
insert image description here
In addition, there is another situation that requires additional attention
. Splicing starts from the last parameter starting with '/', and all previous parameters will be discarded, as shown below:

import os
Path1 = './a'
Path2 = '/b'
Path3 = '/c'
img_path=os.path.join(Path1,Path2,Path3)
print(img_path)
## 以为是 ./a/b/c,但实际是/c

insert image description here

Guess you like

Origin blog.csdn.net/crist_meng/article/details/123718493