sortIdx seems not to work
I am trying to sort elements of 1D mat in descending order. Code seems to work fine in python (openCV) but does not work in C++. In C++, I get zero values as output
My code (C++):
> cv::Mat temp = cvCreateMat(5,
> 1,CV_32F); temp.setTo(10);
> temp.at<float>(2, 0) = 20;
> temp.at<float>(4, 0) = 40; cv::Mat
> ind; cv::sortIdx(temp, ind, CV_SORT_DESCENDING);
Pyhton Code:
kernel = np.ones((7,1), np.int32)
kernel[5]=10
p =cv2.sortIdx(kernel, cv2.SORT_DESCENDING+cv2.SORT_EVERY_COLUMN)
My output index array turns out to be zero with C++ code which is strange ... I tried a lot but don't know what's going on
btw, please do not mix old c-api types with c++ ones, cvCreateMat() returns a CvMat*, and should be avoided.
use Mat temp(5,1,CV_32F); instead (a constructor)
your c++ version is lacking the CV_SORT_EVERY_COLUMN flag:
I am using openCV in big project , where we want the openCV MAT object to be deleted automatically.
I read in documentation that if we declare openCV MAT with cvCreateMat() function then MAT is deleted automatically once u are outside the scope ...
Will it also happen with Mat temp(5,1,CV_32F) ??
yes. cv::Mat has an automatic refcount. please use that, not CvMat* or IplImage*
thanks for that ... this means that MAT object (created by any constructor as discussed above) is deleted automatically .... plz correct me If I am wrong