THRESH_OTSU fails for Python bindings (Bug #1135)


Added by Petter Strandmark over 13 years ago. Updated over 13 years ago.


Status:Done Start date:
Priority:Low Due date:
Assignee:- % Done:

0%

Category:python bindings
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Otsu's method for thresholding does not seem to work for the Python bindings:

I = cv.imread('file.png')

cv.threshold(I, 100, 1, cv.THRESH_BINARY) #Works
cv.threshold(I, 100, 1, cv.THRESH_BINARY + cv.THRESH_OTSU) #Fails
% cv.error: ..\..\..\OpenCV-2.2.0\modules\imgproc\src\thresh.cpp:486: error: (-215) _src.type() == CV_8UC1


History

Updated by Vadim Pisarevsky over 13 years ago

In the latest trunk version the code work fine, as long as the input image is grayscale (note that OpenCV 2.x bindings (cv2 module) have been separated from OpenCV 1.x (cv)):

import cv2

im = cv2.imread("lena.jpg", 0) # make sure the image is grayscale
im2 = cv2.threshold(im, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
cv2.imshow("test", im2r1)
cv2.waitKey()

  • Status changed from Open to Done
  • (deleted custom field) set to obsolete

Updated by Petter Strandmark over 13 years ago

Is there any documentation available for the cv2 module. All documentation I have found for the Python bindings seems outdated.

Updated by Vadim Pisarevsky over 13 years ago

nope. but there is ticket for this :) hopefully, something will be added this week

Also available in: Atom PDF