gpt4 book ai didi

opengl - 将图像纹理加载到CVWindow

转载 作者:行者123 更新时间:2023-12-02 17:52:17 27 4
gpt4 key购买 nike

我在OpenCV中工作,并且有一个要向其中添加图像纹理的窗口。到目前为止,我的代码:

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");

我是OpenGL的新手,并且感到困惑,因此任何有关如何改进它的技巧都将是很棒的,或者从这里到哪里去(如何在窗口上绘制它)。

最佳答案

幸运的是,您无需在OpenGL中进行任何工作即可在窗口中绘制图像:OpenCV已经通过 cvShowImage() 函数提供了此功能。

显示该窗口的代码可能是:

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
}

关于opengl - 将图像纹理加载到CVWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17918776/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com