[OpenCV] Samples 10: imagelist_creator

yaml写法的简单例子。将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中。

写yaml文件。

参考:[OpenCV] Samples 06: [ML] logistic regression 读xml文件。

    {
        /*
         * Jeff --> Load xml.
         *          transform to Mat.
         * FileStorage.
         */
        cout << "loading the dataset...";
        // Step 1.
        FileStorage f;
        if(f.open(filename, FileStorage::READ))
        {
            // Step 2.
            f["datamat"] >> data;
            f["labelsmat"] >> labels;
            f.release();
        }
        else
        {
            cerr << "file can not be opened: " << filename << endl;
            return 1;
        }
        // Step 3.
        data.convertTo(data, CV_32F);
        labels.convertTo(labels, CV_32F);

        cout << "read " << data.rows << " rows of data" << endl;
    }

read xml

/*this creates a yaml or xml list of files from the command line args
 */

#include "opencv2/core/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <string>
#include <iostream>

using std::string;
using std::cout;
using std::endl;

using namespace cv;

static void help(char** av)
{
    cout << "\nThis creates a yaml or xml list of files from the command line args\n"
            "usage:\n./" << av[0] << " imagelist.yaml *.png\n"
         << "Try using different extensions.(e.g. yaml yml xml xml.gz etc...)\n"
         << "This will serialize this list of images or whatever with opencv‘s FileStorage framework" << endl;
}

int main(int ac, char** av)
{
    cv::CommandLineParser parser(ac, av, "{help h||}{@output||}");
    if (parser.has("help"))
    {
        help(av);
        return 0;
    }
    string outputname = parser.get<string>("@output");

    cout << "{yaml} outputname = " << outputname << endl;

    if (outputname.empty())
    {
        help(av);
        return 1;
    }

    Mat m = imread(outputname); //check if the output is an image - prevent overwrites!
    if(!m.empty()){
        std::cerr << "fail! Please specify an output file, don‘t want to overwrite you images!" << endl;
        help(av);
        return 1;
    }

    //Jeff --> write into outputname.
    FileStorage fs(outputname, FileStorage::WRITE);
    fs << "images" << "[";
    for(int i = 2; i < ac; i++){
        //Jeff --> write by "<<", redirection to file stream.
        fs << string(av[i]);
    }
    fs << "]";
    return 0;
}
时间: 2024-10-11 02:26:02

[OpenCV] Samples 10: imagelist_creator的相关文章

鼠标操作[OpenCV 笔记10]

void setMouseCallback(const string& winname, MouseCallback onMouse, void* userdata=0) winname 窗口名字 onMouse 指定窗口每次鼠标事件发生的时候,被调用的函数指针.函数的原型应为void Foo(int event, int x, int y, int flags, void* param). event: 变量EVENT_XXX,例如 EVNET_MOUSEMOVE: 鼠标移动消息 EVENT_

[OpenCV] Samples 05: convexhull

得到了复杂轮廓往往不适合特征的检测,这里再介绍一个点集凸包络的提取函数convexHull,输入参数就可以是contours组中的一个轮廓,返回外凸包络的点集 ---- 如此就能去掉凹进去的边. 对于凸包算法,其中最有名的莫过于Graham扫描算法,它的复杂度为nlog(n) 参考:计算几何之凸包(Algorithm show), 寻找轮廓 高级:Snake模型在轮廓提取中的应用 cvSnakeImage() #include "opencv2/imgproc/imgproc.hpp"

[OpenCV] Samples 04: contours2

要先变为二值图像:cvThreshold 提取轮廓:cvFindContours #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <math.h> #include <iostream> using namespace cv; using namespace std; static void help() { cout

[OpenCV] Samples 13: opencv_version

cv::CommandLineParser的使用. I suppose CommandLineParser::has("something") should be true when the command line has --something in it. ./a.out -h ./a.out --help 打印keys的相关内容. #include <opencv2/core/utility.hpp> #include <iostream> using

Android学习七---Hello OpenCV samples

创建一个能够使用OpenCV JavaCameraView的应用程序来了解基于OpenCV java API 的应用程序的开发流程.有了Android的基础,在程序中需要修改的几个地方1.activity_main.xml 2.AndroidManifest.xml 3.MainActivity.java 一.创建项目 安装创建android程序的方式创建一个blank activity,项目名称为hellosamples,其他采用默认的activity_main.xml,MainActivit

[OpenCV] Samples 12: laplace

先模糊再laplace,也可以替换为sobel等. 变换效果后录成视频,挺好玩. #include "opencv2/videoio/videoio.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <opencv2/core/utility.hpp> #include <ctype.h>

openCV—Python(10)—— 图像阈值化处理

一.函数简介 1.threshold-图像简单阈值化处理 函数原型:threshold(src, thresh, maxval, type, dst=None) src:图像矩阵 thresh:阈值 maxVal:像素最大值 type:阈值化类型 2.adaptiveThreshold-图像自适应阈值化处理 函数原型:adaptiveThreshold(src, maxValue, adaptiveMethod, thresholdType, blockSize, C, dst=None) sr

[OpenCV] Samples 11: image sequence

一帧一帧地读取视频流. VideoCapture sequence(file_video); sequence >> image. #include <opencv2/core/core.hpp> #include <opencv2/videoio/videoio.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using na

[OpenCV] Samples 07: create_mask

鼠标画线,圈地,构造相关mask图片(黑白). 支持鼠标左键右键中间键点击事件. /* * create_mask.cpp * * Author: * Siddharth Kherada <siddharthkherada27[at]gmail[dot]com> * * This tutorial demonstrates how to make mask image (black and white). * The program takes as input a source image