OpenCV Python 计算历史
OpenCV Python calcHist
我想计算image histogram with OpenCV's calcHist function with Python
.
但是不行.
代码:
im = cv2.imread(imPath,0)
hist = cv2.calcHist([im],[0],None,[256],[0,256])
然后我得到 错误 是这样的:
OpenCV Error: Assertion failed (step(dims[-1] == (size_t) CV_ELEM_SIZE(flags))
in create, file opencv/sources/modules/core/src/matrix.cpp line:236
您的代码并没有错 - 这是一些执行相同操作的示例代码 (taken from here):
img = cv2.imread('home.jpg',0)
hist = cv2.calcHist([img],[0],None,[256],[0,256])
因此我认为您的imPath 可能不正确。我建议使用类似于 "C:\myImage.jpg" 的静态文件路径来开始并查看是否出现错误。
试试这个:
import cv2
im = cv2.imread(r'd:\temp.bmp',0)
hist = cv2.calcHist([im],[0],None,256,[0,255])
print im
print hist
我想计算image histogram with OpenCV's calcHist function with Python
.
但是不行.
代码:
im = cv2.imread(imPath,0)
hist = cv2.calcHist([im],[0],None,[256],[0,256])
然后我得到 错误 是这样的:
OpenCV Error: Assertion failed (step(dims[-1] == (size_t) CV_ELEM_SIZE(flags))
in create, file opencv/sources/modules/core/src/matrix.cpp line:236
您的代码并没有错 - 这是一些执行相同操作的示例代码 (taken from here):
img = cv2.imread('home.jpg',0)
hist = cv2.calcHist([img],[0],None,[256],[0,256])
因此我认为您的imPath 可能不正确。我建议使用类似于 "C:\myImage.jpg" 的静态文件路径来开始并查看是否出现错误。
试试这个:
import cv2
im = cv2.imread(r'd:\temp.bmp',0)
hist = cv2.calcHist([im],[0],None,256,[0,255])
print im
print hist