文字包含圖片路徑 及roi感興趣 提取 對圖片分類
//文件類似於上述圖片截圖 第一行為圖片路徑 ,接下來四個為感興趣區域的左上角和右下角座標 ,然後是影象類別。接下來四個又是座標,然後又是類別
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
int k1 = 0, k2 = 0, k3 = 0, k4 = 0, k5 = 0;
string s1;
ifstream qa; qa.open("D:/procedure/ConsoleApplication44/ConsoleApplication44/2007_test.txt");
while (getline(qa,s1)) {
//cout << s << endl;
char s[256];
strcpy(s, s1.c_str());
//char s[] = "C:\\Users\\lbn\\Desktop\\VOC2007\\VOCtest_06-Nov-2007\\VOCdevkit\\VOC2007\\JPEGImages\\000059.jpg 110,210,328,500,3 72,272,115,356,3 125,274,171,353,3";
char* delim = "' ',";
char* tmp, *tmpNext = NULL;
tmp = strtok_s(s, delim, &tmpNext);
vector<string> a;
char saveName[256];
while (tmp != NULL) {
printf("%s\n", tmp);
//cout << tmp << endl;
if(tmp!=NULL){
a.push_back((string)tmp);
tmp = strtok_s(NULL, delim, &tmpNext);}
}
Mat src = imread(a.at(0));
if (a.size() == 1)
continue;
for (size_t i = 1; i < a.size(); i = i + 5)
{
int n0 = atoi(a.at(i).c_str());
int n1 = atoi(a.at(i + 1).c_str());
int n2 = atoi(a.at(i + 2).c_str());
int n3 = atoi(a.at(i + 3).c_str());
int n4 = atoi(a.at(i + 4).c_str());
Mat b = src(Range(n1, n3), Range(n0, n2));
switch (n4) {
case 0:
sprintf(saveName, "D:\\procedure\\ConsoleApplication44\\ConsoleApplication44\\0\\%06d.jpg", k1++);
imwrite(saveName, b);
break;
case 1:
sprintf(saveName, "D:\\procedure\\ConsoleApplication44\\ConsoleApplication44\\1\\%06d.jpg", k2++);
imwrite(saveName, b);
break;
case 2:
sprintf(saveName, "D:\\procedure\\ConsoleApplication44\\ConsoleApplication44\\2\\%06d.jpg", k3++);
imwrite(saveName, b);
break;
case 3:
sprintf(saveName, "D:\\procedure\\ConsoleApplication44\\ConsoleApplication44\\3\\%06d.jpg", k4++);
imwrite(saveName, b);
break;
case 4:
sprintf(saveName, "D:\\procedure\\ConsoleApplication44\\ConsoleApplication44\\4\\%06d.jpg", k5++);
imwrite(saveName, b);
break;
}
}
}
//cout << a.size() <<" "<<a.at(0)<< endl;
return 0;
}