Ask Your Question
0

how to detect moving object ios

asked 2015-06-19 09:11:26 -0600

hi am not familiar with openCV functions and properties so, i cant find way for for detect moving object in video camera with iPhone application please help me .

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-06-20 00:59:45 -0600

Tamajit gravatar image

updated 2015-06-20 02:34:47 -0600

Step 1: follow this to setup your opencv camera

Step 2: add this code to processImage delegate

- (void)processImage:(cv::Mat&)image
{
      //process here
      cv::cvtColor(image, img, cv::COLOR_BGRA2RGB);
      int fixedWidth = 270;
     cv::resize(img, img, cv::Size(fixedWidth,(int)((fixedWidth*1.0f)*   (image.rows/(image.cols*1.0f)))),cv::INTER_NEAREST);

    //update the model
    bg_model->apply(img, fgmask, update_bg_model ? -1 : 0);

    GaussianBlur(fgmask, fgmask, cv::Size(7, 7), 2.5, 2.5);
    threshold(fgmask, fgmask, 10, 255, cv::THRESH_BINARY);

    image = cv::Scalar::all(0);
    img.copyTo(image, fgmask);
}

You'll need to declare following as global variable

cv::Mat img, fgmask;
cv::Ptr<cv::BackgroundSubtractor> bg_model;
bool update_bg_model;

Where, img <- smaller image fgmask <- the mask denotes that where motion is happening update_bg_model <- if you want to fixed your background;

step 3: follow this to learn more.

edit flag offensive delete link more

Comments

i am getting errors :---> no member named "apply" in cv::BackgroundSubtractor AND use of undeclared identifier "fgimg"

nitin umaretiya gravatar imagenitin umaretiya ( 2015-06-20 02:18:54 -0600 )edit

change fgimg = cv::Scalar::all(0); to image = cv::Scalar::all(0);this will remove undeclared identifier "fgimg"..

can you tell me what is your opencv framework version. I have written this code on opencv 3.0.0. if you are using lower version then change bg_model->apply(img, fgmask, update_bg_model ? -1 : 0); to bg_model->operator()(img, fgmask, update_bg_model ? -1 : 0);

Tamajit gravatar imageTamajit ( 2015-06-20 02:31:34 -0600 )edit

'OpenCV', '2.4.9'

nitin umaretiya gravatar imagenitin umaretiya ( 2015-06-20 03:12:46 -0600 )edit

@Tamajit can you please give me source code to open video camera and use of this detection method

nitin umaretiya gravatar imagenitin umaretiya ( 2015-06-20 03:29:12 -0600 )edit

@nitin follow Step 1 (Step 1: follow this to setup your opencv camera) where, VideoCamera.mm is for orientation and ViewController.mm is your viewController class.. in that class you will find _mainDisplay which linked with storyboard(UIImageView)..

Tamajit gravatar imageTamajit ( 2015-06-20 04:19:54 -0600 )edit

now working but in- (void)processImage:(cv::Mat&)imagemethod gotEXC_BAD_ACCESS error in bg_model->operator()(img, fgmask, update_bg_model ? -1 : 0);line

nitin umaretiya gravatar imagenitin umaretiya ( 2015-06-20 06:28:53 -0600 )edit

can you switch to opencv 3.0? or you have to use opencv 2.4.9 only??

Tamajit gravatar imageTamajit ( 2015-06-22 00:05:24 -0600 )edit

what's the logic behind the update_bg_model. Adding snippet how to use update_bg_model will help reads better understanding

Anandyn gravatar imageAnandyn ( 2016-02-10 03:23:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-19 09:11:26 -0600

Seen: 1,626 times

Last updated: Jun 20 '15