BackgroundSubtractorMOG2 bgm-> apply在V​​isual Studio 2017中引发异常 [英] BackgroundSubtractorMOG2 bgm->apply throws exception in Visual Studio 2017

查看:145
本文介绍了BackgroundSubtractorMOG2 bgm-> apply在V​​isual Studio 2017中引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++和opencv的新手,并且难以运行背景减法器模型.我正在使用Visual Studio 2017(VC ++)和opencv 3.2.

I'm new to C++ and opencv and having difficulty running the background subtractor model. I'm using Visual Studio 2017 (VC++) and opencv 3.2.

我需要使用BackgroundSubtractorMOG2,它可以很好地创建模型,但是当我向其传递从编码图像转换而来的新帧时会引发异常(因为我使用的USB3相机不允许直接读取由opencv帧)到cv :: Mat.下面的代码段

I need to use BackgroundSubtractorMOG2 and it creates the model fine but throws exception when I pass it a new frame that is converted from an encoded image (because I'm using a USB3 camera that doesn't allow direct reading of frame by opencv) to cv::Mat. The code snippet is below

if (EncodeRawImage(pRawImage, &frameDesc, imageFormat, &pEncodedImage, &encodedImageSize) == SUCCESS) {
    // Convert current raw image to openCV Mat format for analysis
    auto store = gcnew cli::array<Byte>(encodedImageSize);
    System::Runtime::InteropServices::Marshal::Copy(IntPtr(pEncodedImage), store, 0, encodedImageSize);
    auto stream = gcnew System::IO::MemoryStream(store);

    System::Drawing::Bitmap^ bitmapFrame = safe_cast<System::Drawing::Bitmap ^> (Image::FromStream(stream));
    Mat imgBuf = Mat(bitmapFrame->Width, bitmapFrame->Height, CV_8U, pEncodedImage);
    Mat imgMat = imdecode(imgBuf, CV_LOAD_IMAGE_COLOR);             

    bgm->apply(imgMat , fgMaskMOG);
    returnCode = 1;
 }

例外是

所有者0x0000023afa2a2ec0信息不可用,没有为opencv_world320d.dll加载任何符号> cv :: detail :: PtrOwner *

owner 0x0000023afa2a2ec0 Information not available, no symbols loaded for opencv_world320d.dll> cv::detail::PtrOwner *

存储的0x0000023afa29baa0信息不可用,没有为opencv_world320d.dll加载任何符号> cv :: BackgroundSubtractorMOG2 *

stored 0x0000023afa29baa0 Information not available, no symbols loaded for opencv_world320d.dll> cv::BackgroundSubtractorMOG2 *

即使opencv320d.lib已正确链接,并且在同一程序中为我运行了一些其他基本的opencv示例(例如cv :: subtract,cv :: calcHist等).我想知道是否因为图像尺寸太大(4608x3288)而我正在创建的bitmpaFrame可能有问题?

Even though the opencv320d.lib are linked properly and a few other basic opencv samples run for me in the same program (e.g., cv::subtract, cv::calcHist etc). I wonder if it because the image size is too large (4608x3288) and bitmpaFrame that I'm creating may have an issue?

或者如果我试图以不允许的方式访问流/内存中的图像数据?

Or if I'm trying to access image data in the stream/memory in a way that is not allowed?

推荐答案

即使我在执行断点操作时仍未找到Information字符串,但我还是发现该模型由于图像尺寸过大而引发了异常在我的原始问题(4608x3288)中.我调整图像大小(resize(newImageMat, newImageMat, cv::Size(1000, 1000 * newImageMat.rows / newImageMat.cols), INTER_LINEAR);),错误消失了,模型学习并显示了结果.文字可能是Visual Studio错误,因为我在这里 https://stackoverflow.com/a/7736034/3377101 ?

Even though the Information not found string is still there when I do the breakpoint, I just found that the model was throwing exception because of large image size as I mentioned in my original question (4608x3288). I resizes the image (resize(newImageMat, newImageMat, cv::Size(1000, 1000 * newImageMat.rows / newImageMat.cols), INTER_LINEAR);) and the error is gone and the model learns and shows the result. The text maybe a Visual Studio bug since I was reading about a similar issue here https://stackoverflow.com/a/7736034/3377101?

这篇关于BackgroundSubtractorMOG2 bgm-> apply在V​​isual Studio 2017中引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆