图像数据标签训练处理

使用Opencv进行机器学习过程中经常需要对图像的标签进行处理。比如图像的格式为:cat.jpg 0;dog.jpg 1。

我们提取大量图像的0与1这样标签可以采用下列方法,将标签数据放到设定的Mat格式中,供后续训练使用。

#include<opencv2\opencv.hpp>
#include<iostream>?? ?
#include<string>
#include<vector>
#include<fstream>
#include<opencv2/ml/ml.hpp>

using namespace std;
using namespace cv;
using namespace ml;


int main() {
    //https://blog.csdn.net/qing101hua/article/details/78564201
    Mat m1 = Mat::zeros(8, 1, CV_8UC1);
    ifstream f1("1.txt");
    string s;
    vector<string>v;
    while (getline(f1, s)) {
        //char num[15] = { 0 };
        //strncpy(num, s+(strlen(s) - 2), 1);
        string ss;
        ss = s.substr(s.find(" "));
        v.push_back(ss);


    }
    cout << v[0];

    //imshow("aa", image[0]);//显示第一张图片
    waitKey(0);
    getchar();
    return 0;

}

猜你喜欢

转载自blog.csdn.net/qq_35054151/article/details/81784370