我正在使用从 OpenCV 主干下载的 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;
}
最佳答案
我觉得是线路的问题
imshow(winname, NULL);
您似乎想显示窗口而不显示图像。但是在查看 cv::imshow
时这是行不通的,因为它需要一个 const cv::Mat&
.所以可能要做的是 NULL
转换为 cv::Mat
使用它的构造函数之一,很可能是期待 const IplImage*
的构造函数.但是这个图像指针是空指针,导致构造函数失败。
关于c++ - 如何使用opencv setOpenGlDrawCallback函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8907424/