码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV笔记1

时间:2016-06-19 00:00:59      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:

所用头文件

#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
  1. 显示图片
    void DrawImage() {
        string filepath = "/home/yang/Datasets/lfpw/testset/Path_Images.txt";
        ifstream fin;
        fin.open(filepath.c_str()); //string类型转为字符串类型
        string name;
        while (getline(fin, name)) {
            name.erase(0, name.find_first_not_of("  "));
            name.erase(name.find_last_not_of("  "));
            cv::Mat image = cv::imread(name, 1);//读取图片
            cv::Mat img_gray;
            cvtColor(image, img_gray, CV_BGR2GRAY);
            cv::imshow("result", image);//显示
            cv::waitKey(0);
        }
        fin.close();
    }

     

  2. 播放视频
    void ShowAVI() {
        string filepath = "768x576.avi";
        CvCapture* capture = 0;
        IplImage* iplImg;
        cv::Mat frame, frameCopy;
        capture = cvCaptureFromAVI(filepath.c_str());
        if (!capture)
            cout << "Capture from AVI didn‘t work" << endl;
        while (1) {
            iplImg = cvQueryFrame(capture);
            frame = iplImg;
            if (frame.empty())
                break;
            cv::imshow("result", frame);
            if (cv::waitKey(33) >= 0)//按任意键推出waitKey返回所按键盘的ASCII码
                goto _cleanup_;
        }
        cv::waitKey(0);
        _cleanup_: cvReleaseCapture(&capture);
    }
  3. 视频播放控制

 

OpenCV笔记1

标签:

原文地址:http://www.cnblogs.com/xuanyuyt/p/5597129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!