2011-02-02 8 views
2

OpenCVイメージを受け取ってグレイスケールに変換する関数があります。イメージを断片に分割/カットする方法

void UseLSD(IplImage* destination) 
    { 
    IplImage *destinationForGS = cvCreateImage(cvSize(destination->width, destination->height),IPL_DEPTH_8U,1); 
    cvCvtColor(destination,destinationForGS,CV_RGB2GRAY); 
} 

どのように画像をサイズ10x10ピクセルの画像にカットし、それらを真似するのですか? (幅と高さは10で割り切れないかもしれませんが、画像ごとに1 * hから9 * h + 9 * hピクセルの損失のようなものですが、それは問題ありません) 10 * 10枚の画像を画面に表示します。お願いします。

答えて

4

あなたは、この(反復がテストされていない)のような小片にあなたのイメージを切り抜くことができます:私は、最も簡単な解決策は、関心領域を使用することだと思い

// source image 
IplImage *source = cvLoadImage("lena.jpg", 1); 
int roiSize = 10; 
for(int j = 0; j < source->width/roiSize; ++j) { 
    for(int i = 0; i < source->height/roiSize; ++i) {  
     cvSetImageROI(source, cvRect(i*roiSize, j*roiSize, roiSize, roiSize)); 

     // cropped image 
     IplImage *cropSource = cvCreateImage(cvGetSize(source), source->depth, source->nChannels); 

     // copy 
     cvCopy(source, cropSource, NULL); 

     // ... do what you want with your cropped image ... 

     // always reset the ROI 
     cvResetImageROI(source); 
    } 
} 
+0

大きな画像にOpenCVダイがありますか? – Rella

+0

OpenCVはおそらく、あなたのコンピュータは多分:-)あなたは大きな画像を何と呼んでいますか? –

+0

そして、OpenCV Error:Assertion failedのようなものは何ができますか?(rect.width> = 0 && rect.height> = 0 && rect.x < image-> width && rect.y < image-> height && rect.x + rect.width>不明な関数f ile .. \ .. \ .. \(rect.widt h> 0)&& rect.y + rect.height> =(int)(rect.height> 0) .. \ ocv \ opencv \ src \ cxcore \ cxarray.cpp、3000行 平均? – Rella

4

。ここにサンプルがあります

/* load image */ 
    IplImage *img1 = cvLoadImage("elvita.jpg", 1); 

    /* sets the Region of Interest 
     Note that the rectangle area has to be __INSIDE__ the image 
     You just iterate througt x and y. 
    */ 
    cvSetImageROI(img1, cvRect(x*10, y*10, x*10 + 10, y*10 + 10)); 

    /* create destination image 
     Note that cvGetSize will return the width and the height of ROI */ 
    IplImage *img2 = cvCreateImage(cvGetSize(img1), 
            img1->depth, 
            img1->nChannels); 

    /* copy subimage */ 
    cvCopy(img1, img2, NULL); 

    /* always reset the Region of Interest */ 
    cvResetImageROI(img1); 
関連する問題