首页 > 其他分享 >opencv

opencv

时间:2023-07-07 19:26:34浏览次数:30  
标签:int double frame opencv maxRect cv RECT

/*int main() {
    cv::VideoCapture cap(0);
    if (!cap.isOpened()) {
        cout << "video not exist!" << endl;
        return -1;
    }

   cv:: Mat frame, mask, maskCp;
   cv:: Mat cnimg;

    std::vector<std::vector<cv::Point>> cnts;
    cv::Rect maxRect;
    const double RECT_HW_RATIO = 1.25;    // 人体长宽比阈值
    const double RECT_AREA_RATIO = 0.08;    // 人体占整个图像最小比例阈值
    const double RECT_AREA_RATIO2 = 0.2;    // 人体占整体图像最大比例阈值
   cv:: Ptr<cv::BackgroundSubtractorMOG2> bgsubtractor = cv::createBackgroundSubtractorMOG2();
    bgsubtractor->setHistory(20);
    bgsubtractor->setVarThreshold(100);
    bgsubtractor->setDetectShadows(true);
    bool hasPeople = true;        // 是否有人
    int count = 0;    // 帧数
    int hasPeopleFrameCnt = 0; // 每K帧统计到的有人帧数
    int spaceFrames = 0;        // 每隔125帧统计一次
    const int SPACE_FRAME = 5;

    while (true) {
        cap >> frame;
        cap >> cnimg;
        cv_image<bgr_pixel>pim(cnimg);
        array2d<rgb_pixel>img;
        

        frontal_face_detector detector1 = get_frontal_face_detector();
        std::vector<dlib::rectangle> face = detector1(pim);
        

        resize(frame, frame, cv::Size(frame.cols , frame.rows));
        // 背景更新
        bgsubtractor->apply(frame, mask, 0.002);
        // 中值滤波
        medianBlur(mask, mask, 3);
        // 阈值分割,去阴影
        threshold(mask, mask, 200, 255, cv::THRESH_BINARY);
        // 找轮廓
        maskCp = mask.clone();
        findContours(maskCp, cnts, 0, cv::CHAIN_APPROX_SIMPLE);
        std::vector<cv::Point> maxCnt;
        for (int i = 0; i < cnts.size(); ++i) {
            maxCnt = maxCnt.size() > cnts[i].size() ? maxCnt : cnts[i];
        }
        // 画最大外接矩形
        if (maxCnt.size() > 0) {
            maxRect = boundingRect(maxCnt);
            double rectAreaRatio = (double)maxRect.area() / (frame.cols * frame.rows);
            if ((double)maxRect.height / maxRect.width > RECT_HW_RATIO && rectAreaRatio > RECT_AREA_RATIO &&
                rectAreaRatio < RECT_AREA_RATIO2) {
                cv::rectangle(frame, maxRect.tl(), maxRect.br(), cv::Scalar(0, 255, 0), 2);
                ++hasPeopleFrameCnt;
            }
        }
        ++spaceFrames;
        if (spaceFrames >= SPACE_FRAME) {
            if (hasPeopleFrameCnt > SPACE_FRAME / 8) {
                hasPeople = true;
                cout << count << ":有人" << endl;
            }
            else {
                hasPeople = false;
                cout << count << ":无人" << endl;
            }
            hasPeopleFrameCnt = 0;
            spaceFrames = 0;
        }

       // imshow("frame识别", frame);
        imshow("te",cnimg);

        // imshow("test", gh);

        if (cv::waitKey(10) == 29) {
            break;
        }
    }
    return 0;
};*/
/*******************************************************
 > File Name: main.cpp
 > Author: admin
 > Mail: [email protected]
 > Created Time: Fri 24 Apr 2020 09:46:00 CST
 > Modified Time:2020年07月01日 星期三 15时13分11秒
 > Note: No
*******************************************************/

 

标签:int,double,frame,opencv,maxRect,cv,RECT
From: https://www.cnblogs.com/liliczw2209/p/17535880.html

相关文章

  • opencv dnn学习
     (1条消息)OpenCV中blobFromImage函数详细解释_cv::dnn::blobfromimage_阿卡基YUAN的博客-CSDN博客 ......
  • Qt+opencv dnn模块调用tensorflow模型
    参考网址(1条消息)Qt+opencvdnn模块调用tensorflow模型_vsqt调用tensorflow_街道口扛把子的博客-CSDN博客代码地址:GitHub-Whu-wxy/Simple_Qt_opencv_dnn:UsingdeeplearningmodelwithopencvinQt修改运行后的代码如下:#include<QCoreApplication>#include<opencv2\o......
  • 在全志V853上进行Opencv库的编译步骤
    OpenCV(OpenSourceComputerVision)是一个开放源代码的计算机视觉库,它提供了一系列函数和算法,用于处理图像和视频。通过使用OpenCV,您可以进行各种计算机视觉任务,例如图像处理、对象识别、目标追踪、人脸检测和机器学习等。它提供了底层图像处理功能,以及高级功能和模块,如特征提取、......
  • python opencv无法编码h264、opencv编码的mp4视频无法在网页中播放
    pythonopencv无法编码h264、opencv编码的mp4视频无法在网页中播放,这好像是因为开源许可的协议不同,导致pythonopencv中没有内置h264的编码,无法以h264的格式保存视频。所以我就直接使用webm格式的视频:output_path='output_video.webm'output_codec=cv2.VideoWriter_fourcc......
  • 1 opencv-python图像读写模块
    这个分类记录自己学习opencv的随笔文档,方便以后查询和复习。python-opencv环境配置网上教程很多,此处就不做赘述了,该文档记录opencv最基础的图像读写和显示,工具是jupyternotebook。1opencv中,图像读取函数是imread(filename,flags=None)参数说明:filename:读取图像的路径,通常支......
  • OpenCV4环境配置详细指南(C++)
      OpenCV编程学习今天正式开始,简要的记录一下,希望对大家有用。1:所需文件   开发工具:VisualStudio   下载地址   视觉库:OpenCV  下载地址2:安装  VisualStudio下载好后直接安装,一定要选择C++模块  OpenCV下载好后,双击解压到合适的位置,......
  • 用OpenCV进行传统图像分割
    1.引言欢迎回来,我的图像处理爱好者们!本文我们将直接进入传统图像分析的新领域——图像分割,这是指将图像分成若干具有相似性质的区域的过程,从数学角度来看,图像分割是将图像划分成互不相交的区域的过程。闲话少说,我们直接开始吧!2.基于阈值的分割首先介绍的是基于阈值和基于Otsu的......
  • OpenCV:最流行的图像处理库
    https://www.cnblogs.com/traditional/p/11193524.html楔子关于Python的图像处理,我们之前介绍一个第三方库叫PIL,现在我们来介绍另一个库OpenCV。从功能和性能上来讲,OpenCV要比PIL强大很多,而且OpenCV还可以处理视频。那么下面我们就来介绍一下OpenCV的用法,首先是安......
  • opencv: mask
    (20条消息)pythonopencv图像叠加/图像融合/mask掩模_cv2读取灰度图像和rgb图像叠加_DLANDML的博客-CSDN博客 ......
  • C# OpenCvSharp 图像校正
    效果Demo下载  代码usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingOpenCvSharp;usingOpenCvSharp.Extensions;namesp......