Error using OpenCV: histogram function

Community-Firmware (cfw), Selbstbaucontroller (TX-Pi, ftduino, usw.), usw.
Forumsregeln
Bitte beachte die Forumsregeln!
Antworten
hvn
Beiträge: 256
Registriert: 20 Feb 2011, 11:15

Error using OpenCV: histogram function

Beitrag von hvn » 28 Feb 2021, 16:55

Hi,

I'm trying to use the OpenCV histogram function, but get this error:
hist1 = cv2.calcHist([hist_image1], [0], None, [256], [0, 256])
cv2.error: /home/richard/Projeckte/Fischertechnik/ftcommunity-TXT/buildroot/output/build/opencv3-3.3.0/modules/imgproc/src/histogram.cpp:1500: error: (-210) in function calcHist

Does this mean I should use cv3 instead of cv2 or is this another issue?

Thanks,

hvn

tintenfisch
Beiträge: 472
Registriert: 03 Jan 2018, 22:04

Re: Error using OpenCV: histogram function

Beitrag von tintenfisch » 01 Mär 2021, 18:38

Hi Huub,
hvn hat geschrieben:
28 Feb 2021, 16:55
I'm trying to use the OpenCV histogram function, but get this error:
hist1 = cv2.calcHist([hist_image1], [0], None, [256], [0, 256])
cv2.error: /home/richard/Projeckte/Fischertechnik/ftcommunity-TXT/buildroot/output/build/opencv3-3.3.0/modules/imgproc/src/histogram.cpp:1500: error: (-210) in function calcHist

Does this mean I should use cv3 instead of cv2 or is this another issue?
"import cv2" is still correct with OpenCV 3.3.0, I think the problem has another cause.

cfw has some known issues with OpenCV but I don't know if these effect the above mentioned problem.

How do you get the "hist_image1"?

Best regards,
Lars

hvn
Beiträge: 256
Registriert: 20 Feb 2011, 11:15

Re: Error using OpenCV: histogram function

Beitrag von hvn » 01 Mär 2021, 18:49

Hi Lars,

hist_image1 = cv2.imwrite(filename_res, result)

Which does work...

Thanks,

hvn

tintenfisch
Beiträge: 472
Registriert: 03 Jan 2018, 22:04

Re: Error using OpenCV: histogram function

Beitrag von tintenfisch » 01 Mär 2021, 18:55

hvn hat geschrieben:
01 Mär 2021, 18:49
hist_image1 = cv2.imwrite(filename_res, result)

Which does work...
Aha! cv2.imwrite() returns a boolean, not an image object.

You've to use cv2.imread() which returns an image, i.e.:

Code: Alles auswählen

success = cv2.imwrite(filename_res, result)
if success:
   hist_image1 = cv2.imread(filename_res)
Or use the "result" variable as input for the calcHist function without saving the result first and re-read it.

Best regards,
Lars

hvn
Beiträge: 256
Registriert: 20 Feb 2011, 11:15

Re: Error using OpenCV: histogram function

Beitrag von hvn » 01 Mär 2021, 20:28

Ah ok, didn't think of that. Previously, I just used cv2.imwrite(...) and only for using histogram, I added hist_image1 to it.

Antworten