首页 > 其他分享 >代码备份

代码备份

时间:2023-05-27 13:44:57浏览次数:29  
标签:代码 img int 备份 frame include image cv

#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
#include <dlib/opencv.h>
#include <opencv2/opencv.hpp>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <opencv2\imgproc\imgproc.hpp>
#include <windows.h>
#include <opencv2/opencv.hpp>
#include <cmath>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_io.h>
#include <iostream>
#include <dlib/opencv.h>











/*#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
#include <dlib/opencv.h>
#include <opencv2/opencv.hpp>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>

using namespace dlib;
using namespace std;

int main()
{
    frontal_face_detector detector = get_frontal_face_detector();


    frontal_face_detector detector1 = get_frontal_face_detector();
    shape_predictor pose_mode1;
    deserialize("D:/data/shape_predictor_68_face_landmarks.dat") >> pose_mode1;//文件地址


    image_window win;           //调用window图像处理opencv
    array2d<unsigned char> img;

    string path = "D:/0001.png";

    load_image(img, "D:/0001.png");

    cv::Mat temp = cv::imread(path);

    cv::Mat temp1 = cv::imread(path);

    cv_image<bgr_pixel> cimg(temp);

    //cv_image<bgr_pixel> cimg(temp1);
    


    
    std::vector<rectangle> faces = detector(cimg);
    //pyramid_up(img);
    std::vector<rectangle> dets = detector(img);
    cout << "识别到的人脸数 :" << dets.size() << endl;
    win.clear_overlay();
    win.set_title("facedemo");
    win.set_image(img);
    win.add_overlay(dets, rgb_pixel(255, 0, 0));
    

    cout <<"识别到的人脸数"<< faces.size() << endl;

    std::vector<full_object_detection> shapes;
    for (unsigned long i = 0; i < faces.size(); ++i)
        shapes.push_back(pose_mode1(cimg, faces[i]));

    if (!shapes.empty()) {
        for (int i = 0; i < 68; i++) {
            circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);
            shapes[0].part(i).x();//68个
        }
    }
        
    imshow("Dlib面部识别", temp);
    
    cv::imwrite("D:/pp.png", temp);

    cv::waitKey(0);
    
    cout << "再输入下一张图片" << endl;
    cin.get();
    system("pause");
    return 0;
}*/
/*#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
#include <dlib/opencv.h>
#include <opencv2/opencv.hpp>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>

using namespace dlib;
using namespace std;

int main()
{
    auto path = "D:\\data\\dlib - 19.24\\dlib - 19.24\\examples\\video_frames";

    // Get the list of video frames.  
    std::vector<file> files = get_files_in_directory_tree(path, match_ending(".jpg"));
    std::sort(files.begin(), files.end());

    array2d<unsigned char> img;
    load_image(img, files[0]);      //加载第一帧
    correlation_tracker tracker;    //创建tracker
    //下面所创建的矩形,对果汁盒进行了框选
    tracker.start_track(img, centered_rect(point(93, 110), 38, 86));

    image_window win;
    for (unsigned long i = 1; i < files.size(); ++i)
    {
        load_image(img, files[i]);
        tracker.update(img);    //根据图像,对tracker进行更新

        win.set_image(img);
        win.clear_overlay();
        win.add_overlay(tracker.get_position());
        Sleep(100);
    }
}*/

//using namespace dlib;
using namespace std;
using namespace cv;
int main() {
    VideoCapture cap("D:/viedio/002.mp4");
    if (!cap.isOpened()) {
        cout << "video not exist!" << endl;
        return -1;
    }
    //frontal_face_detector detector = get_frontal_face_detector();
    //std::vector<rectangle> faces = detector(cap);
    long FRAMECNT = cap.get(CAP_PROP_FRAME_COUNT);
    Mat frame, mask, maskCp;
    vector<vector<Point>> cnts;
    Rect maxRect;
    const double RECT_HW_RATIO = 1.25;    // 人体长宽比阈值
    const double RECT_AREA_RATIO = 0.08;    // 人体占整个图像最小比例阈值
    const double RECT_AREA_RATIO2 = 0.2;    // 人体占整体图像最大比例阈值
    Ptr<BackgroundSubtractorMOG2> bgsubtractor = 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 (++count < FRAMECNT - 10) {
        cap >> frame;
        resize(frame, frame, Size(frame.cols / 4, frame.rows / 4));
        // 背景更新
        bgsubtractor->apply(frame, mask, 0.002);
        // 中值滤波
        medianBlur(mask, mask, 3);
        // 阈值分割,去阴影
        threshold(mask, mask, 200, 255,THRESH_BINARY);
        // 找轮廓
        maskCp = mask.clone();
        findContours(maskCp, cnts, 0, CHAIN_APPROX_SIMPLE);
        vector<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) {
                rectangle(frame, maxRect.tl(), maxRect.br(), 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("mask", mask);
        if (waitKey(10) == 29) {
            break;
        }
    }
    return 0;
};

 

标签:代码,img,int,备份,frame,include,image,cv
From: https://www.cnblogs.com/liliczw2209/p/17436629.html

相关文章

  • 代码生成器
    代码生成器原理是读取表结构,根据表结构的字段名称、数据类型、注释生成实体类,然后根据实体类生成controller和servicefreemarker标签参数${pramName}:根据controller中定义的值,对pramName进行替换<#if>:当结果为true时才会进行展示<p>你好,<#ifuserName=="lyra">......
  • WIN10 由于找不到mfc140u.dll,无法继续执行代码
    最近遇到win10提示mfc140u.dll找不到,总是弹窗的问题.网上一番百度搜索后发现给的方法都不能很好的解决,DLL修复工具需登录且收费去下载mfc140u.dll根本不可能找到,都是垃圾病毒,危险⚠️经过google搜索后找到比较科学的方法:`thefileMFC140.DLLispartdtheVisualC++Redistr......
  • 【无人机任务分配】基于合同网协议(CNP算法)实现多无人机具有时间窗口和优先级约束任务
    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。......
  • 高精度加法(含代码)
    高精度加法例1例如:1111111111111+9,列成竖式,1111111111111+9---------------------------先算个位,1+9=10,满10,向十位进1。1111111111111+9......
  • Python 使用Seaborn画图,代码正常不出图
    不得不说,这个库画出来的图也太好看了。目前还没有很懂这个库,但是需要注意的是我在用完plt之后引入这个,图片一直出不来真的困扰我很久啊。终于找到了救命的办法参考链接:https://blog.csdn.net/qq_56039091/article/details/124024286......
  • Gitea Docker 备份恢复
    关于GiteaDocker备份恢复,可以参考以下链接:Gitea官方文档:https://docs.gitea.io/en-us/backup-and-restore/DockerHub上的Gitea镜像文档:https://hub.docker.com/r/gitea/gitea/GitHub上的Gitea仓库:https://github.com/go-gitea/gitea以下是一些关于GiteaDocker备......
  • DBeaver连接mysql数据库和备份恢复那些事
    引言上一篇文章,主要讲解的是如何使用DBeaver连接oracle数据库,同时和大家扩展的聊了聊oracle的监听器了。在DBeaver这套文章的第1篇中,我就介绍了为什么要引入DBeaver?为了替换掉团队中现有的商用软件,比如大家连接mysql时,最喜欢使用的navicat。既然要替换掉navicat,那DBeaver就要满足na......
  • [ESP] ESP-IDF WiFi配网(SoftAP+HTTPD)代码备注
    ESP-IDFWiFi配网(SoftAP+HTTPD)代码备注主要是为了方便了解实际代码层面的配网协议是什么样的,所以文档记录的基本上是代码片段。ESP-IDF的版本是V5.0使用SoftAP传输时,为了允许服务发现,必须在开始配置之前初始化mDNS。protocomm_security一共有3个选项,这里只说了protoco......
  • 一些源代码管理工具介绍
    首先,是源代码管理工具能为我们做什么。源代码管理工具的部分作用如下:1.能够追踪一个项目从诞生到一直定案的过程2.记录一个项目所有内容的变化3.方便查阅特定版本的修订情况4.源代码管理工具可以判断每一行代码里面每一个字符是谁写的。而我们使用源代码管理工具,1.由于使用简单,......
  • 源代码管理工具--GitHub
    一.GitHub简介Github是一个基于Git的代码托管平台,主要为开发者提供基于Git仓库的版本托管服务,并提供一个web界面。其由ChrisWanstrath,PJHyett与TomPreston-Werner三位开发者在2008年4月创办。总部位于美国旧金山。使用上,付费用户可以建私人仓库,免费用户只能使用公共仓库,也......