gpt4 book ai didi

c++ - 基于OpenCV的背景提取

转载 作者:太空宇宙 更新时间:2023-11-03 22:14:58 24 4
gpt4 key购买 nike

我试图制作一个基于 openCV 的程序,它提取视频中的背景,我的问题是程序在强度(光)上有一个小的变化作为整个背景的变化,这是我写的代码它基于 OpenCV 样本,

   #include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2\calib3d\calib3d.hpp>
#include <iostream>


int main(int argc, const char** argv){
cv::VideoCapture cap(0);
cv::BackgroundSubtractorMOG2 bg_model;
bg_model.history = 10000;
bg_model.bShadowDetection = false;
cv::Mat img, fgmask,fgimg,smooth;
bool update =true;
int key =0;

while(key !=27){
cap >> img;
cv::blur(img,smooth,cv::Size(20,10));
//update the model
if(fgimg.empty())
fgimg.create(img.size(),img.type());
bg_model(smooth,fgmask,update ? -1 :0);
fgimg = cv::Scalar::all(0);
img.copyTo(fgimg,fgmask);


cv::imshow("fgimg",fgimg);
cv::imshow("fgmask",fgmask);
cv::imshow("img",img);
std::cout << bg_model.backgroundRatio << std::endl;
if(key == 'x')
update= !update;
if( update){
std::cout << "update on " <<std::endl;
}
else{
std::cout << "update off "<<std::endl;
}
key = 0;
key = cv::waitKey(10);
}
}

有谁知道如何将程序的灵敏度降低到强度。

在此先感谢您的帮助!!

最佳答案

您可以使用 initialize 方法更改 bg_modelnmixturesminArea 值来调整灵敏度

如链接所示:http://www710.univ-lyon1.fr/~eguillou/documentation/opencv2/classcv_1_1_background_subtractor_m_o_g2.html

关于c++ - 基于OpenCV的背景提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16830905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com