Search code examples
c#c++opencvthreshold

opencvsharp Cv.Threshold returns void even for ThresholdType.Otsu


So I have used cvThreshold in the C++ version of OpenCV and when using CV_THRESHOLD_OTSU, i get a double as a return showing me what the threshold used was.

In OpenCVSharp, the function is defined returning void only. Is it that i'm misusing it or we just dont get that option anymore?


Solution

  • The Threshold function call in OpenCVsharp was written to return void which wouldnt deal with the thresholdType_Otsu.

    it needs to be modified to

    public static double Threshold( CvArr src, CvArr dst, double threshold, double max_value, ThresholdType threshold_type )
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null)
                throw new ArgumentNullException("dst");
            return CvInvoke.cvThreshold(src.CvPtr, dst.CvPtr, threshold, max_value, threshold_type);
        }
    

    This works when a threshold is returned as well as for other cases where the return is void.