我正在使用从OpenCV trunk下载的OpenCV 2.3.2库。我想使用setOpenGlDrawCallback函数来显示OpenGL场景。当我编译下面的简单代码时,我得到以下错误:
OpenCV Error: Assertion failed (depth >= 0 && depth <= CV_32F) in unknown function, file ..\..\..\opencv\modules\core\src\opengl_interop.cpp, line 736
这段代码出了什么问题?
// углы поворота
float angx=55, angy=45;
float angstep=10;
String winname = "opengl";
// opengl callback
void on_opengl(void* param)
{
glLoadIdentity();
glTranslated(0.0, 0.0, -1.0);
glRotatef( angx, 1, 0, 0 );
glRotatef( angy, 0, 1, 0 );
glRotatef( 0, 0, 0, 1 );
static const int coords[6][4][3] = {
{ { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } },
{ { +1, +1, -1 }, { -1, +1, -1 }, { -1, +1, +1 }, { +1, +1, +1 } },
{ { +1, -1, +1 }, { +1, -1, -1 }, { +1, +1, -1 }, { +1, +1, +1 } },
{ { -1, -1, -1 }, { -1, -1, +1 }, { -1, +1, +1 }, { -1, +1, -1 } },
{ { +1, -1, +1 }, { -1, -1, +1 }, { -1, -1, -1 }, { +1, -1, -1 } },
{ { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } }
};
for (int i = 0; i < 6; ++i) {
glColor3ub( i*20, 100+i*10, i*42 );
glBegin(GL_QUADS);
for (int j = 0; j < 4; ++j) {
glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], 0.2 * coords[i][j][2]);
}
glEnd();
}
}
int _tmain(int argc, _TCHAR* argv[])
{
namedWindow(winname,CV_WINDOW_OPENGL | CV_WINDOW_FREERATIO | CV_GUI_NORMAL );
setOpenGlDrawCallback(winname.c_str(),on_opengl);**
while (true)
{
char key = (char)waitKey(10);
if( key == 27 )
break;
// вращаем
switch( key )
{
case 'w':
angx+=angstep;
break;
case 's':
angx-=angstep;
break;
case 'a':
angy+=angstep;
break;
case 'd':
angy-=angstep;
break;
}
// обновить рендер
imshow(winname, NULL);
}
return 0;
}
答案 0 :(得分:1)
我认为问题就在于行
imshow(winname, NULL);
似乎您想显示窗口而不显示图像。但是在查看cv::imshow
的signtaure时,这不起作用,因为它需要const cv::Mat&
。所以可能做的是使用其中一个构造函数将NULL
转换为cv::Mat
,最可能的是期望const IplImage*
的构造函数。但是这个图像指针是空指针,这使构造函数失败。