I had a little problem debugging the following code today , After debugging many times, I finally found the solution , Let's share it with you :

Debug code :

res_path='G:/coding_data/Model_Zoo/PoolNet/training_testing_data/DUTS-TE/DUTS-TE-Results/'
gt_path='G:/coding_data/Model_Zoo/PoolNet/training_testing_data/DUTS-TE/DUTS-TE-Mask/'
res_list=os.listdir(res_path) #print(res_list) mae=[] for i in
range(len(res_list)): #print('res_list',res_list[i])
r_name=res_path+res_list[i] #print('r_name:',r_name)
g_name=gt_path+res_list[i][:-13]+'.png' #print('res_list[i]:', res_list[i])
#print(g_name) res=cv2.imread(r_name) h,w,_=res.shape res = cv2.cvtColor(res,
cv2.COLOR_RGB2GRAY) res=res/255 gt=cv2.imread(g_name) gt = cv2.cvtColor(gt,
cv2.COLOR_RGB2GRAY) gt=gt/255 mae.append(sum(sum(abs(res-gt)))/(h*w))
print(sum(sum(abs(res-gt)))/(h*w)) return sum(mae)/len(mae)
 

problem :
cv2.error: OpenCV(3.4.2)
c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:253: error:
(-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) &&
VDepth::contains(depth) in function 'cv::CvtHelper<struct
cv::Set<3,4,-1>,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper'
In response to this problem , The solution given by the blog is to check the path name , The general path name is not correct .

After checking the path name several times , There is no problem finding the path to the code , Finally, through the output of each read in r_name and g_name The name of the picture found the problem :

The cause of this problem is :

The pictures in the two paths do not correspond , Namely :res_path  and  gt_path  The pictures below are not one-to-one , There is a lack of pictures

 

Solution :

        Delete the missing pictures in the folder or add extra pictures

 

 

 

 

 

 

 

 

Technology