Opengl 将图像纹理加载到CVD窗口
我在OpenCV中工作,有一个窗口,我想在其中添加图像纹理。到目前为止,我的代码是:Opengl 将图像纹理加载到CVD窗口,opengl,opencv,Opengl,Opencv,我在OpenCV中工作,有一个窗口,我想在其中添加图像纹理。到目前为止,我的代码是: void display(void) { GLuint texture[1]; IplImage *image; image=cvLoadImage("Particle.png"); if(!image){ std::cout << "image empty" << std::endl; } else { g
void display(void) {
GLuint texture[1];
IplImage *image;
image=cvLoadImage("Particle.png");
if(!image){
std::cout << "image empty" << std::endl;
} else {
glGenTextures(1, texture);
glBindTexture(1, GL_TEXTURE_2D );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Set texture clamping method
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
cvReleaseImage(&image);
}
int main(int argc, char**argv)
{
display();
}
//window to draw the texture on
cvNamedWindow("video");
void显示(void){
胶合纹理[1];
IplImage*图像;
image=cvLoadImage(“Particle.png”);
如果(!图像){
幸运的是,在窗口中绘制图像不需要在OpenGL中做任何工作:OpenCV已经在函数中提供了此功能
显示窗口的代码可能是:
if(!image)
{
std::cout << "image empty" << std::endl;
}
else
{
cvNamedWindow("image"); // Create the window
cvShowImage("image", image); // Display image in the window
cvWaitKey(); // Display window until a key is pressed
}
if(!image)
{
std::非常感谢您的回复!由于某些原因,窗口没有显示,但至少错误消失了,可能是因为某些原因,现在我的图像不存在了。@AndreaF我怀疑窗口显示并很快消失。添加cvWaitKey()
将使窗口保持打开状态,直到您按下某个键为止(请参阅我的编辑)如果我能回答,你会接受吗?如果你能,你应该使用C++ API代替C API。还有一个空的图像,但是会算出,然后应该工作。我会切换,但是我没有工作过多的CV::MAT,因为我在做彩色跟踪,不确定我是否能像C.一样轻松地使用C++,至少是COLO。你的跟踪教程似乎是C语言。C++ API比C API更容易使用。只有你不熟悉C++的情况下才会出现。但是我建议你切换,特别是如果你刚开始的话。