简体   繁体   English

直方图的python和opencv2问题

[英]python and opencv2 issue with histograms

I am having some trouble with histograms and and opencv2 with python. 我在使用直方图和使用Python的opencv2时遇到了一些麻烦。 I took some code from here: http://opencvpython.blogspot.com/2012/04/drawing-histogram-in-opencv-python.html 我从这里获取了一些代码: http : //opencvpython.blogspot.com/2012/04/drawing-histogram-in-opencv-python.html

here is the code: 这是代码:

import cv2
import numpy as np

img = cv2.imread('lena.bmp')
h = np.zeros((512,512,3))                                   

bins = np.arange(256).reshape(256,1)
color = [ (255,0,0),(0,255,0),(0,0,255) ]
for ch, col in enumerate(color):
    hist_item = cv2.calcHist([img],[ch],None,[256],[0,255])
    cv2.normalize(hist_item,hist_item,0,255,cv2.NORM_MINMAX)
    hist=np.int32(np.around(hist_item))
    pts = np.column_stack((bins,hist))
    cv2.polylines(h,[pts],False,col)
    print pts

where lena.bmp comes from this link. lena.bmp来自此链接的位置。

Problems are: 问题是:

1) cv2.polylines(h,[pts],False,col) fails with error: 1)cv2.polylines(h,[pts],False,col)失败并显示错误:

OpenCV Error: Assertion failed (src.dims <= 2 && esz <= (size_t)32) in transpose

2) printing pts i see that values are different from values i get using gimp to analyze r, g and b histograms. 2)打印点,我发现值与我使用gimp分析r,g和b直方图得到的值不同。 And here i mean that bins have different values. 这里我的意思是垃圾箱具有不同的值。

Any idea? 任何想法?

最终,我使这段代码在另一台计算机上工作,所以代码正确,但是我的环境中缺少某些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM