使用C ++和opengl进行图像处理,试图理解代码 [英] Image processing with C++ and opengl, trying to understand a code

查看:104
本文介绍了使用C ++和opengl进行图像处理,试图理解代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习使用C ++和OpenGL进行图像处理。

我遇到了这个部分,



I'm learning image processing using C++ and OpenGL.
I encountered this part,

int main(int argc, char *argv[])
{
  unsigned char* image; 
    image = SOIL_load_image("Images/image.png", &width, &height, 0, SOIL_LOAD_RGBA);
    if(image == NULL) exit(0); //if loaded image fail
  }

static void createImages(void)
{
    unsigned char *p;

    p = image;
    for(int i = 0; i < height*width; i++) {     
        if(*p == 0 && *(p+1) == 0) { //(p+1)==0-->Green pixel =0, what is *p==0 ?
         //some commands to replace pixels value
     {...

}

条件中* p == 0是什么意思?检查指向图像的指针为0?

这是否意味着检查图像是否已加载?



我尝试过:



我理解完整代码的其余部分,除了* p == 0部分。

what does *p == 0 in condition mean ? checking pointer to the image as 0 ?
Does that mean checking if the image is loaded ?

What I have tried:

I understand the rest of the full code except for the *p==0 part.

推荐答案

在您的示例 * 中是解除引用运算符 - 维基百科 [ ^ ]。因为 p 的类型为 unsigned char * ,它将访问 unsigned char 指向 p 。它类似于使用 p [0] *(p + 1)类似于 p [1]
In your example * is the Dereference operator - Wikipedia[^]. Because p is of type unsigned char * it will access the unsigned char to which p is pointing. It is similar to using p[0] and *(p+1) is similar to p[1].


加载检查是
if(image == NULL) exit(0); //if loaded image fail

您的代码检查内存是否为p并且p + 1指向为0.这是两个字节,因此它是一个16位值或WORD。通常是解释内存到某些格式信息。这取决于图像的数据格式。为此你必须阅读SOIL_load_image的规格细节。



这种代码模式通常用于识别颜色的某些区域并对其进行操作。



缺少一些重要的代码,即改变p。

Your code checks whether the memory to which p and p+1 is pointing is 0. This are two bytes, so it is a 16-bit value or WORD. Normally is that done to interpret memory to some format information. That is depending on the data format of your image. For that you must read the specifications details of SOIL_load_image.

Such code pattern is often used to identify some areas of a color and manipulate it.

Some important code is missing which is about changing p.


这篇关于使用C ++和opengl进行图像处理,试图理解代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆