Buggy Mat.at with 3 indexes (Bug #2233)


Added by NoRG Zotto over 12 years ago. Updated over 12 years ago.


Status:Cancelled Start date:2012-08-03
Priority:Normal Due date:
Assignee:- % Done:

0%

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

Description

Such example code (simplified from cornerDetector_Demo.cpp) raises assert:

Mat myHarris_dst = Mat::zeros(Size(100, 100), CV_32FC(6) );
float lambda_1 = myHarris_dst.at<float>( 0, 0, 0 );

OpenCV Error: Assertion failed (elemSize() == (((((DataType<_Tp>::type) & ((512- 1) << 3)) >> 3) + 1) << ((((sizeof(size_t)/4+1)*16384|x3a50)>> ((DataType<_Tp>::type) & ((1 << 3) - 1))*2) & 3))) in unknown function, file C:\usr\local\opencv-249\include\opencv2/core/mat.hpp, line 593

Two-indexes "at" looks like not bugged. I'm on master branch, 2.42 also bugged. Maybe I just missed with syntax?


Associated revisions

Revision 7942494f
Added by Vadim Pisarevsky almost 11 years ago

Merge pull request #2233 from palindromoroz:BGSubtract_KNN_new_code

History

Updated by Daniil Osokin over 12 years ago

I tried to reproduce that, but this two lines of code works as well as usual. No any asserts. Suppose, that you have assert by another reason.

Updated by NoRG Zotto over 12 years ago

Maybe you run in release mode? CV_DbgAssert raises only in Debug mode, error located here

template<typename _Tp> inline _Tp& Mat::at(int i0, int i1, int i2)
{
    CV_DbgAssert( elemSize() == CV_ELEM_SIZE(DataType<_Tp>::type) ); /// <-  here raised
    return *(_Tp*)ptr(i0, i1, i2);
}

Or maybe your compiler removed this block when optimizing.

Please, try this.

    Mat myHarris_dst2 = Mat::zeros(Size(100, 100), CV_32FC(6) );
    myHarris_dst2.at<float>( 5, 5, 5 ) = 100.f;
    float lambda_1 = myHarris_dst2.at<float>( 5, 5, 5 );

Or best just try compile and run samples\cpp\tutorial_code\TrackingMotion\cornerDetector_Demo.cpp.
I compiling by MS VS2010 x86.

Updated by Daniil Osokin over 12 years ago

at<i, j, k> works with 3D matrix, but you have 2D, so that's the reason. It's not a Bug, good place for that kind of question is http://answers.opencv.org/questions/, you can use it in future.

  • Target version deleted (3.0)
  • Assignee deleted (Vadim Pisarevsky)

Updated by Vadim Pisarevsky over 12 years ago

to access n-th channel of element (x,y) of 100x100 6-channel matrix, you need to use

myHarris_dst.at<float>(y, x)[n] instead of myHarris_dst.at<float>(y, x, n).

  • Status changed from Open to Cancelled

Also available in: Atom PDF