From 5ac5412e847a0abaeaf83c3a0299e68ffaec10f1 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Thu, 22 Feb 2018 13:12:04 +0100 Subject: [PATCH 1/1] opencv_trail_effect.cpp: fix showing the background When showing the background OpenCV would fail with this message: OpenCV Error: Assertion failed (channels() == CV_MAT_CN(dtype)) in copyTo, file /build/opencv-lY8WRY/opencv-3.2.0+dfsg/modules/core/src/copy.cpp, line 259 terminate called after throwing an instance of 'cv::Exception' what(): /build/opencv-lY8WRY/opencv-3.2.0+dfsg/modules/core/src/copy.cpp:259: error: (-215) channels() == CV_MAT_CN(dtype) in function copyTo Initializing the background to the same format of the input frame seems to fix this. --- opencv_trail_effect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencv_trail_effect.cpp b/opencv_trail_effect.cpp index 5a4e928..5fec5dc 100644 --- a/opencv_trail_effect.cpp +++ b/opencv_trail_effect.cpp @@ -176,7 +176,7 @@ int main(int argc, char *argv[]) if (*segmentation_method == "background") { segmentation = new MOG2Segmentation(inputVideo, background_learn_frames); if (show_background) { - cv::Mat background; + cv::Mat background(frame_size, inputVideo.get(CV_CAP_PROP_FORMAT)); ((MOG2Segmentation *)segmentation)->getBackgroundImage(background); trail->setBackground(background); -- 2.1.4