ios – 如何使用openCV检测实时摄像机中的移动物体

ios – 如何使用openCV检测实时摄像机中的移动物体,第1张

概述我正在使用openCV为我的ios应用程序检测实时摄像机中的移动物体,但我不熟悉openCV的使用请帮助我.任何其他方式也欢迎. - (void)viewDidLoad { [super viewDidLoad]; self.videoCamera.delegate = self; self.videoCamera = [[CvVideoCamera alloc] ini 我正在使用openCV为我的ios应用程序检测实时摄像机中的移动物体,但我不熟悉openCV的使用请帮助我.任何其他方式也欢迎.

- (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检测实时摄像机中的移动物体所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1008041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存