开发者

OpenCV set ROI in camera streaming window

I'd like to set Region of Interest in window with image captured from camera.. How to do that? I'm us开发者_如何学编程ing C# with OpenCVSharp and Visual C#.

Something like that:

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);
            }


I don't know about C#, but here's how I would do it in C++ (with OpenCV 2). Hopefully the translation is easy. The statement Mat roiRect = frame(Rect(200,200,100,100)); creates a header that shares data with frame but only in the region of interest.

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;
}


I would create a rectangle on the top of the image, following this link could help.

Use the created rectangle to crop the selected area:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜