Linux下Opencv入门编程一 (图像取反)

来源:互联网 发布:怎么看python安装的库 编辑:程序博客网 时间:2024/06/06 01:27

实现图片像素点的取反操作

--------------------------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
 int main(int argc, char ** argv)
{      IplImage *pImage;
        int i,j;
        if (argc != 3)
       {
         printf("Format Error:  ./run input.bmp  output.bmp\n");
         return 1;
        }
       if((pImage = cvLoadImage(argv[1], 1)) == 0)             //加载图片
       {
         printf("Load Picture Failed!(%s)\n", argv[1]);
       }
      for (i = 0; i < pImage->height; i++)
         for( j = 0; j < ((pImage->width*3 + 3)/4)*4; ++j)         //注意字节对齐
          {
            *(pImage->imageData + i*((pImage->width*3 + 3)/4)*4 + j) ^= 0xFF;
          }
       cvSaveImage(argv[2], pImage, 0);               //保存图片
       printf("Image Process OK!\n");
       return 0;
}
 -----------------------------------------------------------------------------------makefile:  gcc main.c -o run -lopencv_highgui -Wall

0 0
原创粉丝点击