本文主要是介绍错误:When the input arrays in add/subtract/multiply/divide functions have different types, ...,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
"When the input arrays in add/subtract/multiply/divide functions have different "
报错:"When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'arithm_op'"
在写热力图绘制函数时,遇到以下错误:
Traceback (most recent call last):File "/media/wzg/Disk3T/ano_voting_cascade/inference_heatmap.py", line 177, in <module>heatmap_img = Vis_obj.intensity_heatmap(background_img=frame,intensity_map=intensity_map,blue_mask_weight=0.3,heat_map_weight=0.5)File "/media/wzg/Disk3T/ano_voting_cascade/src/tools/Class_Visualization.py", line 444, in intensity_heatmapheatmap_base = cv2.addWeighted(blue_mask, blue_mask_weight, background_img_norm, 1 - blue_mask_weight, 0).astype(np.uint8)
cv2.error: OpenCV(4.2.0) /io/opencv/modules/core/src/arithm.cpp:693: error: (-5:Bad argument) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'arithm_op'
原因:错误的主要原因是 cv2.addWeighted(img,0.01,img0,0.99,0, CV_32F) 的两幅图像的格式不一致。
修改方法1:强制把两幅图的格式转为相同的数据格式就行了,我用的是“.astype(np.uint8)”,如下
blue_mask = cv2.rectangle(background_img.copy(), (0, 0), background_img.shape[0:2], (0, 0, 255), -1).astype(np.uint8)
heatmap_base = cv2.addWeighted(blue_mask, blue_mask_weight, background_img_norm, 1 - blue_mask_weight, 0).astype(np.uint8)
修改方法2:在加权和时强迫格式转换
img2 = cv2.addWeighted(img,0.01,img0,0.99,0, dtype = cv2.CV_32F)
参考:https://blog.csdn.net/qq_35250841/article/details/108320967
这篇关于错误:When the input arrays in add/subtract/multiply/divide functions have different types, ...的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!