Linux下Opencv入門程式設計一 (影象取反)
阿新 • • 發佈:2019-02-09
實現圖片畫素點的取反操作
--------------------------------------------------------------------------------------------------------------------
#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