标签:解决方案 设置 class not 通道 取图 ram open 放大
使用OpenCV读取图片代码如下
img = imread(m_fileName); if (img.empty()) { fprintf(stderr, "Can not load image %s\n", m_fileName); return -1; } //设置长宽 int width = img.cols; int height = img.rows; int channel = img.channels(); printf(" depth %d\n", channel); //获取图像指针 int pixellength = width * height * channel; pixels = new GLubyte[pixellength]; memcpy(pixels, img.data, pixellength * sizeof(char)); //imshow("OpenCV", img); glGenTextures(1, &m_textureObj); glBindTexture(m_textureTarget, m_textureObj); //必须一个RGB 一个BGR(opencv的mat类的颜色通道是BGR) 否则会出现颜色偏差 glTexImage2D(m_textureTarget, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, pixels); //纹理放大缩小使用线性插值 glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(m_textureTarget, 0); free(pixels);
运行程序时,出现了两个问题:
glTexImage2D(m_textureTarget, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, pixels);
标签:解决方案 设置 class not 通道 取图 ram open 放大
原文地址:https://www.cnblogs.com/farewell-farewell/p/9581674.html