opencv cvtColor报错

训练yolov5的时候如果启用了Albumentations库可能会出现:

    cv2.cvtColor(im_hsv, cv2.COLOR_HSV2BGR, dst=im)  # no return needed
TypeError: Expected Ptr for argument 'dst'

或者

    cv2.cvtColor(im_hsv, cv2.COLOR_HSV2BGR, dst=im)  # no return needed
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'cvtColor'
> Overload resolution failed:
>  - Layout of the output array dst is incompatible with cv::Mat
>  - Expected Ptr for argument 'dst'

原因是之前的操作使得im在内存中不连续,在augment_hsv之前加一行解决:

img = np.ascontiguousarray(img)

你可能感兴趣的:(opencv cvtColor报错)