c# - OpenCV 在相机流窗口中设置 ROI

标签 c# opencv

我想在窗口中使用从相机捕获的图像设置感兴趣区域。该怎么做? 我将 C# 与 OpenCVSharp 和 Visual C# 结合使用。

类似的东西:

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

最佳答案

我不了解 C#,但这是我在 C++(使用 OpenCV 2)中的做法。希望翻译容易。语句 Mat roiRect = frame(Rect(200,200,100,100)); 创建一个 header ,它与 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;
}

关于c# - OpenCV 在相机流窗口中设置 ROI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7131949/

相关文章:

c# - 使用 Visual Studio 设计器 - "Object reference not set to an instance of an object"(Visual Studio 2008)

c# - 使用 Azure 移动服务中的脱机表时 CreatedAt 属性为 null

Python OpenCV 2.4 写入半完整的PNG视频帧

matlab - 按关键点方向删除错误匹配

opencv - imshow 断言错误

c# - 具有多个 StartsWith 子句的 LINQ 查询?

c# - 在 C# 中验证签名请求

opencv - 查找图片是否包含颗粒噪声

apk - App Bundle 是否足够,或者 APK 分割是否足以减少 APK 大小?

c# - Fluent NHibernate 自动映射私有(private)/ protected 属性作为 Id