2011-07-20 7 views
0

OpenCVでは、画像をロードしてピクセル値を取得したいと思います。入力画像のピクセルは別の1つの配列に割り当てられます。この配列の値は再構成され、出力画像が表示されます。その入力ピクセルへのいくつかの操作、私はそのピクセルの対応する出力を取得したい。これに使用されるコマンドは何ですか?opencvで画像を読み書きする

答えて

2

こんにちは、私はあなたがイメージcvSaveImage(outF,image2) cvNamedWindow(file,1) cvShowImage(file,image)を保存し、表示する必要があるいくつかの他のstuffsがありますが、次の

#include "cv.h" 
#include "highgui.h" 
#include <stdio.h> 

IplImage *image=0, *image2=0; 

int main(int argc, char** argv) { 
    char* file, *outF; 
    //Usage: filename.exe imagefile outputimage 
    if (argc == 3) { 
     file=argv[1]; 
     outF=argv[2]; 
    }else { 
     exit(0); 
    } 
    //Loading file 
    if((image = cvLoadImage(file, 1)) == 0) 
     return -1; 
    // creating image in greyscale 
    image2 = cvCreateImage(cvSize(image->width,image->height),IPL_DEPTH_8U,1); 
    myFunction(); 
} 

void myFunction() { 
    uchar *pix; // To store pixel value temporarily 
    uchar *out; 
    //// NOW U CAN ACCESS EACH Pixel 
    for (int posY=0; posY<image->height;posY++) { 
     for (int posX=0; posX<image->width;posX++) { 
      pix=&((uchar *)(image->imageData+posY*image->widthStep))[posX]; //this is to get value 
      out=&((uchar *)(image2->imageData+posY*image2->widthStep))[posX]; 

      //Do your stuff here ---Example 
      // to access original image file use 
      // uchar c = *pix; 

      // this assgins your output image your manipulations 
      *out= someValue[x][y]; //(0-255) your assignment from your array, It should work 
      //---------------------- 


     } 
    } 
} 

を行うだろう。 hereの詳細。

関連する問題