使用OpenCV Python的2D图像中的深度错误 [英] Depth error in 2D image with OpenCV Python

查看:119
本文介绍了使用OpenCV Python的2D图像中的深度错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV和Python计算图像(ndarray)中的Canny Edges.

I am trying to compute the Canny Edges in an image (ndarray) using OpenCV with Python.

slice1 = slices[15,:,:]
slice1 = slice1[40:80,60:100]
print slice1.shape
print slice1.dtype
slicecanny = cv2.Canny(slice1, 1, 100)

输出:

(40, 40)
float64
...
error: /Users/jmerkow/code/opencv-2.4.6.1/modules/imgproc/src/canny.cpp:49: 
error: (-215) src.depth() == CV_8U in function Canny

由于某种原因,我收到了以上错误.有什么想法吗?

For some reason I get the above error. Any ideas why?

推荐答案

Slice1将需要强制转换或创建为uint8. CV_8U只是uint8数据类型的别名.

Slice1 will need to be casted or created as a uint8. CV_8U is just an alias for the datatype uint8.

import numpy as np
slice1Copy = np.uint8(slice1)
slicecanny = cv2.Canny(slice1Copy,1,100)

这篇关于使用OpenCV Python的2D图像中的深度错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆