- (voID)vIEwDIDLoad { [super vIEwDIDLoad]; self.vIDeoCamera.delegate = self; self.vIDeoCamera = [[CvVIDeoCamera alloc] initWithParentVIEw:self.vIEw]; self.vIDeoCamera.defaultAVCaptureDeviceposition = AVCaptureDevicepositionBack; self.vIDeoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288; self.vIDeoCamera.defaultAVCaptureVIDeoOrIEntation = AVCaptureVIDeoOrIEntationPortrait; self.vIDeoCamera.defaultFPS = 30; self.vIDeoCamera.grayscaleMode = NO; [self.vIDeoCamera start];// cv::BackgroundSubtractormog2 bg;}- (voID)processImage:(cv::Mat&)image{ //process here cv::cvtcolor(image,img,cv::color_BGRA2RGB); int fixeDWIDth = 270; cv::resize(img,cv::Size(fixeDWIDth,(int)((fixeDWIDth*1.0f)* (image.rows/(image.cols*1.0f)))),cv::INTER_NEAREST); //update the model bg_model->operator()(img,fgmask,update_bg_model ? -1 : 0); GaussianBlur(fgmask,cv::Size(7,7),2.5,2.5); threshold(fgmask,10,255,cv::THRESH_BINARY); image = cv::Scalar::all(0); img.copyTo(image,fgmask);}
我是openCV的新手,所以我不知道该怎么办.
解决方法 将此代码添加到processImage委托:- (voID)processImage:(cv::Mat&)image{ //process here cv::cvtcolor(image,cv::color_BGRA2RGB); int fixeDWIDth = 270; cv::resize(img,cv::INTER_NEAREST); //update the model bg_model->apply(img,update_bg_model ? -1 : 0); GaussianBlur(fgmask,fgmask);}
您需要将以下声明为全局变量
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;
Please refer this URL获取更多信息.
总结以上是内存溢出为你收集整理的ios – 如何使用openCV检测实时摄像机中的移动物体全部内容,希望文章能够帮你解决ios – 如何使用openCV检测实时摄像机中的移动物体所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)