2011-08-20 39 views
1

我想在窗口中設置感興趣區域,從相機捕獲圖像..如何做到這一點? 我使用C#與OpenCVSharp和Visual C#。OpenCV在相機流式傳輸窗口中設置投資回報率

類似的東西:

using (CvCapture cap = CvCapture.FromCamera(0)) // device type + camera index 
using (CvWindow v = new CvWindow("Live Stream")) 
while (CvWindow.WaitKey(10) < 0) 
      { 
       using (IplImage src = cap.QueryFrame()) 
       v.Image = src; 
       // Then set ROI and send it to picturebox 
       pictureBox.Image = BitmapConverter.ToBitmap(ROI); 
      } 

回答

1

我不知道C#做的,但這裏是我會怎麼做它在C++(帶OpenCV的2)。希望翻譯很容易。聲明Mat roiRect = frame(Rect(200,200,100,100));創建一個標頭,該標頭與frame共享數據,但僅限於感興趣的區域。

using namespace cv; 

int main(int argc, const char * argv[]) { 

    VideoCapture cap; 
    if(argc > 1) 
     cap.open(string(argv[1])); 
    else 
     cap.open(0); 
    Mat frame; 
    namedWindow("video", 1); 
    for(;;) { 
     cap >> frame; 
     if(!frame.data) 
      break; 

     //Create the region of interest 
     Mat roiRect = frame(Rect(200,200,100,100)); 
     //Do something with the region of interest 
     roiRect *= 0.4; 

     imshow("video", frame); 
     if(waitKey(30) >= 0) 
      break; 
    } 

    return 0; 
} 
0

我會在圖像的頂部創建一個矩形,以下this link能有所幫助。

使用創建矩形裁剪所選區域:

Rectangle cropArea new Rectangle(0, 0, 10, 10); 
    Bitmap bmpImage = new Bitmap(img); 
    Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);