Ask Your Question

kuppy's profile - activity

2020-10-11 15:12:40 -0500 received badge  Student (source)
2017-05-29 10:01:50 -0500 received badge  Enthusiast
2017-05-22 04:30:38 -0500 commented question Background subtraction

frame and frame_mask have the same size

2017-05-21 18:19:46 -0500 asked a question Background subtraction

I try to subtract using bitwise_and and BackgroundSubtractor but I have this error:

OpenCV Error: Assertion failed ((mtype == CV_8U || mtype == CV_8S) && _mask.sameSize(*psrc1)) in cv::binary_op, file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\arithm.cpp, line 241

code:

Mat frame1;
Mat frame_mask;

bool bSuccess = cap.read(frame1); 

if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
pMOG2->apply(frame1, frame_mask);
Mat kernel = Mat::ones(frame1.size(), CV_8UC1);
erode(frame1, frame_mask, kernel);
bitwise_and(frame1, frame1, frame, frame_mask);

Error occurs when I use bitwise_and(...).

I used OpenCV 3.2.0 and VS15. I'm pretty new at the OpenCV, so could you please say, what I do wrong? Thank you.

2017-04-10 16:35:31 -0500 commented answer Opencv error: Assertation failed when findContours is used

Thank you, but after I replaced another problem has arisen in the same row: Unhandled exception at 0x00007FFB72FFD5B8 (ucrtbase.dll) in try opencv.exe: An invalid parameter was passed to a function that considers invalid parameters fatal.

2017-04-09 12:28:52 -0500 asked a question Opencv error: Assertation failed when findContours is used

I'm using visual studio 2015 and openCV 3.2 I have caught this exception:

OpenCV Error: Assertion failed ((_contours.kind() == _InputArray::STD_VECTOR_VECTOR || _contours.kind() == _InputArray::STD_VECTOR_MAT || _contours.kind() == _InputArray::STD_VECTOR_UMAT)) in cv::findContours, file C:\build\master_winpack-build-win64-vc14\opencv\modules\imgproc\src\contours.cpp, line 1902

when I used findConours method.

Code:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"

#include <stdlib.h>
#include <stdio.h>


using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{

    VideoCapture cap(0);
    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT);

    namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    int counter = 0;
    char filename[512];
    while (1)
    {
        Mat frame;

        bool bSuccess = cap.read(frame); // read a new frame from video

        if (!bSuccess) //if not success, break loop
        {
            cout << "Cannot read a frame from video stream" << endl;
            break;
        }

        Mat im;
        // Convert image to YCrCb
        cvtColor(frame, im, COLOR_RGB2YCrCb);

        //skin tone
        Mat skin;
        inRange(im, Scalar(0,133,77), Scalar(255,173,127),skin);

        Mat contours;
        findContours(skin,contours,RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);

        for (int i = 0; i<contours.rows; i++)
        {
            for (int j = 0; i < contours.cols; j++)
            {
                double area = contourArea(j);
                if (area > 1000)
                {
                    drawContours(frame, contours, i, Scalar(0, 250, 0), 3);
                }
            }
        }

        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        char c = waitKey(33);
        if (c == 27) 
        {
            cout << "esc key is pressed by user" << endl;
            break;
        }
    }
    destroyWindow("MyVideo");
    cap.release();
    return 0;
}

How can I solve this?