[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
今天调试下面这段代码的时候遇到了个小问题,在自己多次调试后终于找到解决方案,下面分享给大家:
调试代码:
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)
问题:
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'
针对该问题,查阅博客给出的方案都是检查路径名称,一般是路径名称不对。
我在多次检查确认路径名称后,发现代码的路径并没有问题,最后通过输出每次读入 r_name和 g_name的图片名称找到问题所在:
该问题产生的原因为:
两个路径下图片不对应,即:res_path 和 gt_path 下的图片不是一一对应的,存在缺少图片的情况
解决方案:
删掉文件夹中缺少的图片或者补充多余的图片即可