qq_26350387
qq_26350387
采纳率0%
2017-05-04 12:35 阅读 879

100分送上,大神们谁帮帮小弟如何把下面代码中检测图像改为检测视频

100

#include "FastDPM.h"
#include

vector yuStdDirFiles(string DirName, vector FileExtensions);
string trim_file_name(string FileName, int FLAG);
string jsonStr;//全局变量保存json字符串

int main()
{

string  img_dir = "d:\\image";

string extensions[] = { ".jpg" };
vector<string>  img_extensions(extensions, extensions + 1);
vector<string>  imgnames = yuStdDirFiles(img_dir, img_extensions);

/* II. Perform Part_Model based detection */

FastDPM PM("person_final2007.txt");

bool    flag = false;

vector<double> dvec;
double total = 0;
for (unsigned i = 0; i<imgnames.size(); i++)
{
    string  img_name = imgnames[i];
    Mat img_uint8 = imread(img_name.c_str());
    if (img_uint8.empty())
    {
        cout << "Cannot get image " << img_name << endl;
        getchar();
        return -2;
    }
    cout << "Processing " << trim_file_name(img_name, 0) << endl;

    clock_t start, finish;
    double  during;
    start = clock();


    Mat img = PM.prepareImg(img_uint8);

    PM.detect(img, 0.248062f, true, true, img_name);

    finish = clock();
    during = (double)(finish - start) / CLOCKS_PER_SEC;
    dvec.push_back(during);

    cout << "------------------------------------------------------------" << endl;
    /*cout << ::jsonStr << endl;*/

    if (PM.detections.empty())
        continue;
    flag = true;
    char key = waitKey(1);
    if (key == 27)
        break;

}
for (double var : dvec)
{
    total += var;
}
cout << "time:" << total / dvec.size() << endl;


cout << "Finished!" << endl;
if (flag)
    waitKey();
else
    _getch();

return  0;

}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • qq_26350387 qq_26350387 2017-05-04 12:43

    这是我打开摄像头,并把视频检测出来后整理成一帧帧图片(1秒1帧),现在问题是如何将这个图片抛给上面检测图片的代码呢

    CvCapture *capture = cvCreateCameraCapture(0);
    cvNamedWindow("camera", CV_WINDOW_AUTOSIZE);
    IplImage *img;
    char file_name[15];
    int i;
    while (1)
    {
    for (i = 0; i<99999; i++)
    {
    img = cvQueryFrame(capture);
    if (!img)
    break;
    cvShowImage("camera", img);
    char c = cvWaitKey(1000);
    if (c == 27)
    {
    cvReleaseCapture(&capture);
    cvDestroyWindow("hh");
    exit(0);
    }//按esc退出

            sprintf(file_name, "d:\\image\\%05d.jpg", i);//d盘根目录下生成,其中i就是图片的编号,每次运行程序都会从0开始编起。
            cvSaveImage(file_name, img);
            FastDPM PM("person_final2007.txt");
    
    
    
    
        }    
    }
    
    点赞 评论 复制链接分享
  • shen_wei shen_wei 2017-05-05 03:36
  • caozhy 从今以后生命中的每一秒都属于我爱的人 2017-05-05 03:40

    首先用ffmpeg一类的库,将视频中的关键帧提取出来,变成图片,再套用你的代码

    点赞 评论 复制链接分享

相关推荐