I am using the BackgroundsubtractorMOG() to basically extract a mask to separate out the foreground. I am then using convexHull() on the mask to locate the position of a moving object.
But i am getting the following error:
openCV Error: Assertion failed (nelems >= 0 && (depth == CV_32F || depth == CV_32S)) in convexHull, file /home/ameya/OpenCV2.4.2/modules/imgproc/src/contours.cpp, line 1947
terminate called after throwing an instance of 'cv::Exception'
what(): /home/ameya/OpenCV2.4.2/modules/imgproc/src/contours.cpp:1947: error: (-215) nelems >= 0 && (depth == CV_32F || depth == CV_32S) in function convexHull
I have checked the no. of elements as well as type-casted the mask matrix. But the error still persists.
Has anyone encountered a similar problem before. I am using OpenCV 2.4.2
Use this format, it will help (notice typecasting to Mat):
convexhull(Mat(inputarray),hull,0,0)
are you calling convexhull on your mask image there ?
it's supposed to work with point2d(or index) vectors, eg. from findContours()
Related
I use VideoWriter::write to wrote a Mat with the pixel format of CV_32FC3,but it would always cause an error when VideoWriter::write was called.
Then i found that any pixel format of CV_8UC* would always succeed.
But Why?
Error Msg Was:
OpenCV(4.2.0) Error: Assertion failed (!fixedType() || ((Mat*)obj)->type() == mtype) in cv::debug_build_guard::_OutputArray::create, file C:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\matrix_wrap.cpp, line 1195
Any answer will be helpful
video is simply not stored at such high colour depths
Quoted From #MarkSetchell
I have a matrix D which I would like to set to zero where another matrix T is zero and keep intact otherwise. In numpy, I'd do this:
D[T==0]=0;
but with cv::Mat, not sure how to do it. I tried this:
D&=(T!=0);
with this result:
OpenCV Error: Assertion failed (type == B.type()) in gemm, file /build/opencv-AuXD2R/opencv-3.3.1/modules/core/src/matmul.cpp, line 1558
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-AuXD2R/opencv-3.3.1/modules/core/src/matmul.cpp:1558: error: (-215) type == B.type() in function gemm
Is the problem that I am mixing numeric types? I also tried this then (D is CV_32F as well, which I verified by outputting T.type(), 5):
cv::Mat TnotZero;
cv::Mat(T!=0).convertTo(TnotZero,CV_32F);
D&=TnotZero;
with the same result.
What is the solution?
I have a vector of images and vector of descriptor values extracted using HOG descriptor in Opencv:
vector<Mat> images;
vector< vector < float> > v_descriptorsValues;
These vectors are previously initialized with proper images and values. The part of the code that causes an Opencv error :
Mat reData(images.size(), v_descriptorsValues[0].size(),true);
for (int i=0; i< images.size(); i++)
Mat(v_descriptorsValues[i]).copyTo(reData.row(i));
And the Opencv error i got:
OpenCV Error: Assertion failed (!fixedSize() || ((Mat*)obj)->size.operator()() == _sz) in unknown function, file ..\..\..\src\opencv\modules\core\src\matrix.cpp, line 1344
Actually in the last line of code i want to copy all the element of v_descriptorsValues to reData Mat.
Any idea that can solve the problem?
I need to resize an IplImage and convert it into a CvMat of different depth, this is the code I've written so far:
void cvResize2(IplImage *imgSrc, IplImage *imgDst)
{
IplImage *imgTemp;
imgTemp = cvCreateImage( cvGetSize( imgSrc ), IPL_DEPTH_64F, 1 );
cvScale( imgSrc, imgTemp, 1/255., 0.0 );
cvResize( imgTemp, imgDst );
}
The source image is grayscale, the destination one is 64F bit deep. cvScale only scales between images of same size, hence the temp image.
The program rises the following exception when invoking cvResize:
OpenCV Error: Assertion failed (func != 0) in resize, file /tmp/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp, line 1488
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp:1488: error: (-215) func != 0 in function resize
I can't figure out why, I've checked that the images respect the conditions imposed
src: 512x384, 8 depth
tmp: 512x384, 64 depth
dst: 64x64, 64 depth
Any clues?
Thanks in advance
You may have found a bug. I can reproduce it on my end, too (Ubuntu 64-bit, OpenCV-2.1.0). If you use 32-bit floating point precision, it works, but crashes with 64-bit floats. My recommendation is to update your OpenCV to the most recent version and see if the problem goes away. If not, then build the library in debug mode and step through the function that is throwing the assertion. From looking at the culprit source in cvimgwarp.cpp, it looks like it's unable to find an interpolation method to use for the destination image.
I'm trying to implement the fourier transformation in frequency domain.
I used getOptimalDFTSize accordingly, and I copied the image and mask, in bigger images, suitable for fourier transformation. I used the sample code from here as a reference.
Now, I have to separate the real and imaginary part, and to perform pixelwise multiplication of the image imaginary part with the mask imaginary part, and the same for the real part.But when I try to do so, I get the following error message:
OpenCV Error: Assertion failed (type == srcB.type() && srcA.size() == srcB.size()) in mulSpectrums, file /build/buildd/opencv-2.1.0/src/cxcore/cxdxt.cpp, line 1855
/build/buildd/opencv-2.1.0/src/cxcore/cxdxt.cpp:1855: error: (-215) type == srcB.type() && srcA.size() == srcB.size() in function mulSpectrums
The code is following:
//fourier transfromation of real and imaginary part
Mat complex_image, real_image, complex_mask, real_mask;
cv::dft(new_image, complex_image, DFT_COMPLEX_OUTPUT);
cv::dft(new_image, real_image, DFT_REAL_OUTPUT);
cv::dft(new_mask, complex_mask, DFT_COMPLEX_OUTPUT);
cv::dft(new_mask, real_mask, DFT_REAL_OUTPUT);
//pixelwise multiplication
Mat multiplied_complex, multiplied_real;
cv::mulSpectrums(complex_image, complex_mask, multiplied_complex, DFT_COMPLEX_OUTPUT );
cv::mulSpectrums(real_image, real_mask, multiplied_real, DFT_REAL_OUTPUT);
What am I doing wrong here?
Image and mask should have same size (width and height) and (most probably this is problem) type. So if it is different type you need to convert one of them so they have equal type.