BackgroundSubtractorMOG2 bgm->apply 在 Visual Studio 2017 中引发异常 [英] BackgroundSubtractorMOG2 bgm->apply throws exception in Visual 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 相机,它不t 允许通过 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;
}
例外是
owner 0x0000023afa2a2ec0 信息不可用,没有为 opencv_world320d.dll 加载符号> cv::detail::PtrOwner *
owner 0x0000023afa2a2ec0 Information not available, no symbols loaded for opencv_world320d.dll> cv::detail::PtrOwner *
stored 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?
推荐答案
即使在我做断点时信息未找到字符串仍然存在,我只是发现模型因为我提到的大图像尺寸而抛出异常在我原来的问题 (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 在 Visual Studio 2017 中引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!