Ask Your Question

CubbyBluePen's profile - activity

2019-10-06 07:06:04 -0600 received badge  Popular Question (source)
2015-03-25 03:43:48 -0600 commented question ERROR: Background Subtraction from Video

then, what i need to do?

2015-03-25 03:18:30 -0600 commented question ERROR: Background Subtraction from Video

actually i had copy the coding and change it a little bit and i am the beginner in using opencv.. anything wrong in my coding?

2015-03-25 03:09:50 -0600 commented question ERROR: Background Subtraction from Video

it dont has any error but it only display and play the video..coding for background subtraction doesnt take place..

2015-03-25 02:58:05 -0600 received badge  Editor (source)
2015-03-25 01:50:29 -0600 asked a question ERROR: Background Subtraction from Video

image description I had ran a coding for background subtraction from the video for offline. I used openCV 2.4.9 and Visual Studio 2013 to run the coding. The video can display and play but the problem is the coding for background subtraction does not functioning. Can anybody help me what is the wrong for my coding? Someone had tell me the error is

if (strcmp(argv[1], "-vid") == 0)
    {
        //input data coming from a video
        processVideo(argv[2]);
    }

so, what i need to do?

// BackgroundSubtraction_Success.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include "stdafx.h"
#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\flann\flann.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\photo\photo.hpp>
#include <opencv2\video\video.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\objdetect\objdetect.hpp>
#include <opencv2\calib3d\calib3d.hpp>
#include <opencv2\ml\ml.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\contrib\contrib.hpp>
//#include "opencv\cv.h"
//#include <opencv2\core\core_c.h>
//#include <opencv2\highgui\highgui_c.h>
//#include <opencv2\imgproc\imgproc_c.h>


using namespace cv;
using namespace std;

//global variables
Mat frame; //current frame
Mat fgMaskMOG; //fg mask generated by MOG method
Ptr <BackgroundSubtractorMOG> pMOG; //MOG Background Subtractor

int keyboard;

//function declarations
void help();
void processVideo(char*Background);

void help()
{
    cout
        << "----------------------------------------" << endl
        << endl
        << "This program begins with Motion Detection" << endl
        << "using Background Subtraction" << endl
        << endl
        << "------------------------------------------" << endl;

}

int main(int argc, char*argv[])
{
    VideoCapture cap("C:/Users/user/Documents/Visual Studio 2013/Projects/cobaan/NewOpenCV_Success/sample1.avi"); // open the video file for reading

    if (!cap.isOpened())  // if not success, exit program
    {
        cout << "Cannot open the video file" << endl;
        return -1;
    }

    //cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

    double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

    cout << "Frame per seconds : " << fps << endl;

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

    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 the frame from video file" << endl;
            break;
        }

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

        if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
        {
            cout << "esc key is pressed by user" << endl;
            break;
        }
    }
    //print help information
    help();
    //check for the input parameter correctness
    if (argc != 3)
    {
        cerr << "incorrect input list" << endl;
        cerr << "exiting..." << endl;
        return EXIT_FAILURE;
    }

    //create GUI windows
    namedWindow("Frame");
    namedWindow("FG Mask MOG");

    //call the constructor
    BackgroundSubtractorMOG bgmog;
    bgmog(frame, fgMaskMOG);

    //create background subtractor objects
    //pMOG = createBackgroundSubtractorMOG(); //MOG approach

    if (strcmp(argv[1], "-vid") == 0)
    {
        //input data coming from a video
        processVideo(argv[2]);
    }
    else
    {
        //error in reading input parameter
        cerr << "Please check the input parameters." << endl;
        cerr << "Exiting..." << endl;
        return EXIT_FAILURE;
    }

    //destroy GUI windows
    destroyAllWindows();
    return EXIT_SUCCESS;
}

//call video
void processVideo(char* MyVideo)
{

    //create the capture object
    VideoCapture capture(MyVideo);
    if (!capture.isOpened())
    {
        //error in opening the video input
        cerr << "Unable to open video file: " <<MyVideo << endl;
        exit(EXIT_FAILURE);
    }

    //read input data ...
(more)
2015-02-27 22:26:27 -0600 commented question background subtraction

i had done with the step, but it continue gives me some errors:

Error   9   error LNK1120: 7 unresolved externals   
Error   8   error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" (?_interlockedExchangeAdd@cv@@YAHPAHH@Z) referenced in function "public: void __thiscall cv::Ptr<class cv::BackgroundSubtractorMOG>::release(void)" (?release@?$Ptr@VBackgroundSubtractorMOG@cv@@@cv@@QAEXXZ)
Error   3   error LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray@cv@@QAE@ABVMat@1@@Z) referenced in function "void __cdecl processVideo(char *)" (?processVideo@@YAXPAD@Z)
2015-02-25 05:22:07 -0600 commented question background subtraction

When I delete that part, it will gives me a lot of errors: error C2039:'apply' : is not memeber of 'cv::BackgroundSubtractorMOG' error C3861: 'createBackgroundSubtractorMOG':identifier not found intelliSense: class "cv::BackgroundSubtractorMOG" has no memeber "apply" IntelliSense identifier "createBBackgroundSubtractorMOG" is undefined

may i have a right coding without any error?

2015-02-25 05:11:52 -0600 commented question Viola Jones using opencv

i had tried to run but i get this error:

error C2601: 'detectAndDisplay' : local function are illegal

what i should do?

2015-02-25 03:55:02 -0600 commented question Viola Jones using opencv

it is for c++?

2015-02-25 03:21:57 -0600 asked a question Viola Jones using opencv

I am a beginner for the openCV and VS. So, I need a help to give me the sample of coding for face detection using Viola Jones algorithm by using OpenCV and VS2013. Can someone help me please. Thanks..

2015-02-25 03:21:39 -0600 asked a question background subtraction

I am the beginner for the opencv and c++. I had ran my coding.

//////////////////////////////////
// BackgroundSubtraction.cpp : Defines the entry point for the console application.
//////////////////////////////////

#include <stdio.h>
#include "stdafx.h"
#include "opencv\cv.h" 
#include <opencv2\core\core.hpp>
#include <opencv2\flann\flann.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\photo\photo.hpp>
#include <opencv2\video\video.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2\objdetect\objdetect.hpp>
#include <opencv2\calib3d\calib3d.hpp>
#include <opencv2\ml\ml.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\contrib\contrib.hpp>
#include <opencv2\core\core_c.h>
#include <opencv2\highgui\highgui_c.h>
#include <opencv2\imgproc\imgproc_c.h>
#include <iostream>

using namespace cv;
using namespace std;

//global variables
Mat frame; //current frame
Mat fgMaskMOG; //fg mask generated by MOG method
Ptr <BackgroundSubtractor> pMOG; //MOG Background Subtractor

//Background Subtractor
class BackgroundSubtractor: public Algorithm
{
    public:
    virtual ~BackgroundSubtractor();
    virtual void operator()(InputArray image, OutputArray fgmask, double learningRate = 0);
    virtual void getBackgroundImage(OutputArray backgroundImage) const;
};


int keyboard;

//function declarations
void help();
void processVideo(char*videoFilename);

void help()
{
    cout
        << "----------------------------------------" << endl
        << endl
        << "This program begins with Motion Detection" << endl
        << "using Background Subtraction" << endl
        << endl
        << "------------------------------------------" << endl;

}

int main(int argc, char*argv[])
{
    //print help information
    help();
    //check for the input parameter correctness
    if (argc != 3)
    {
        cerr << "incorrect input list" << endl;
        cerr << "exiting..." << endl;
        return EXIT_FAILURE;
    }

    //create GUI windows
    namedWindow("Frame");
    namedWindow("FG Mask MOG");

    //create background subtractor objects
    pMOG = createBackgroundSubtractorMOG(); //MOG approach

    if (strcmp(argv[1], "-vid") == 0)
    {
        //input data coming from a video
        processVideo(argv[2]);
    }
    else
    {
        //error in reading input parameter
        cerr << "Please check the input parameters." << endl;
        cerr << "Exiting..." << endl;
        return EXIT_FAILURE;
    }

    //destroy GUI windows
    destroyAllWindows();
    return EXIT_SUCCESS;
}

void processVideo(char* videoFilename)
{
    //create the capture object
    VideoCapture capture(videoFilename);
    if (!capture.isOpened())
    {
        //error in opening the video input
        cerr << "Unable to open video file: " << videoFilename << endl;
        exit(EXIT_FAILURE);
    }

    //read input data ESC or 'q' for quitting
    while ((char)keyboard != 'q' && (char)keyboard != 27)
    {
        //read the current frame
        if (!capture.read(frame))
        {
            cerr << "Unable to read next frame" << endl;
            cerr << "Exiting..." << endl;
            exit(EXIT_FAILURE);
        }

        //update the background model
        pMOG->apply(frame, fgMaskMOG);

        //get the frame number and write it on the current frame
        stringstream ss;
        rectangle(frame, cv::Point(10, 2), cv::Point(100, 20), cv::Scalar(255, 255, 255), -1);
        ss << capture.get(CV_CAP_PROP_POS_FRAMES);
        string frameNumberString = ss.str();
        putText(frame, frameNumberString.c_str(), cv::Point(15, 15), FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 0));

        //show the current frame and fg masks
        imshow("Frame", frame);
        imshow("FG Mask MOG", fgMaskMOG);

        //get input from the keyboard
        keyboard = waitKey(30);
    }
    //delete capture object
    capture.release();
}

////////////////////////////////

It produce errors such as:

IntelliSense: "BackgroundSubtractor" is ambigious
IntelliSense: identifier "createBackgroundSubtractorMOG" is undefined
IntelliSense: class "cv::BackgroundSubtractor" has no member "apply"

I really need helps for my project. Thanks.