1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to calculate histogram of an image?

Discussão em 'Python' iniciado por Stack, Novembro 30, 2025.

  1. Stack

    Stack Membro Participativo

    How can I solve the below error?

    import cv2

    img= cv2.imread('/home/monojit/Desktop/crop.jpg')
    hsv= cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

    hist= cv2.calcHist([hsv],[0,1],None,[256],[0,256])
    print(hist)

    cv2.imshow('img',hsv)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


    But on execution the get the following error:

    Traceback (most recent call last):
    File "/home/monojit/Desktop/hisCalc.py", line 6, in <module>
    hist= cv2.calcHist([hsv],[0,1],None,[256],[0,256])
    error: OpenCV(3.4.1) /home/monojit/Desktop/OpenCV/modules/imgproc/src/histogram.cpp:1782: error: (-215) csz == 0 || csz == dims in function calcHist


    How do I solve the error?

    Continue reading...

Compartilhe esta Página