Emgu CV中的肖像模式



我正在创建一个基于相机的winforms应用程序,其中我使用了emgucv。

我想在单击按钮时以肖像模式捕获图像。

我尝试了:

cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 190);
cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 250);

,但图像仍然保持在景观模式中,仅尺寸从640 x 480降低到某些176 x 130,但我想要肖像图像。

那么谁能告诉我如何应对这个问题?

cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 190);
cap.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 250);

您使用的代码上面的代码只会更改图像的大小(捕获的帧),您没有得到确切的大小可能是因为纵横比维护了。

现在捕获肖像模式,在捕获后将当前的框架旋转90度,然后对其进行重新尺寸以适合图像框。

代码将是这样的

public Form1()
{
    InitializeComponent();

    _capture = new Capture();   
    Application.Idle += ProcessFrame;
}
private void ProcessFrame(object sender, EventArgs arg)
{
    Image<Bgr, Byte> currentFrame = _capture.QueryFrame();
    currentFrame =currentFrame.Rotate(90,new Bgr(255,255,255),true);
    // other code to the task you want to achieve like displaying in ImageBox etc.

}

在此处检查官方文档

最新更新