c语言使用小技巧之读取图片路径和label

主要是我记性不好 记下这些常用的以免自己忘记。

1. 每个图片路径后面跟一个label 


   那么读取方式为:
 fstream fin;
fin.open("ss.txt", ios::in | ios::app);
string stemp, int n;
fin>>stemp>>in;

#include <iostream>
#include <opencv2/opencv.hpp>
#include <vector>
#include <fstream>
#include <time.h>
#include "../FaceGenderV.h"
using namespace cv;
using namespace std;
#define MAXFACECOUNT 50

string gender[2] = { "female", "male" };


int main()
{
	void * handle = FGV_Init("GPU");
	if (handle == NULL)
	{
		printf("Init failed, exit!");
		exit(0);
	}

	string imagefolder_path="//home//ggj//ggj//data//2015workshop";
        FILE *fid=NULL;
 	fid=fopen("2015workshop_bbox_1221_val.txt","w");
        fstream fin;
	fin.open("gender_val.txt",ios::in|ios::app);
        string stemp;
	int n;
       
        char imgpath[260];
	int imagenum=0;

	while(!fin.eof())
	{
		
		 fin>>stemp>>n;
		cout<<"in "<<n<<endl;
		cout<<"stemp "<<stemp<<endl;
		cout<<"imagenum "<<imagenum<<endl;
		imagenum=imagenum+1;
	
		sprintf(imgpath, "%s/%s",imagefolder_path.c_str(),stemp.c_str());
		cv::Mat img = imread(imgpath);

		FR_Rect *rect = new FR_Rect[MAXFACECOUNT];
		clock_t begin = clock();
		int facecount = FGV_Detect(handle, img.data, img.cols, img.rows, rect);	//
		clock_t end = clock();
		printf("detect time cost: %f ms \n", double(end - begin));
		printf("facecount = %d\n", facecount);
		if (facecount == 0)
		
			continue;
		else
		{
			for (int i = 0; i < facecount; i++)
			{
			
				Rect m_rect(rect[i].left, rect[i].top,rect[i].width,rect[i].height);
				Mat ROI;
				cout<<"rect[i].left "<<rect[i].left<<endl;
				cout<<"rect[i].top "<<rect[i].top<<endl;
				cout<<"img.rows "<<img.rows<<endl;
				cout<<"img.cols "<<img.cols<<endl;
				cout<<"rect[i].width "<<rect[i].width<<endl;
				cout<<"rect[i].height "<<rect[i].height<<endl;
				if(rect[i].width>img.rows)
					continue;
				if(rect[i].height>img.cols)
					continue;
				if(rect[i].left>img.rows)
					continue;
				if(rect[i].top>img.cols)
					continue;
				if((rect[i].top+rect[i].height)>=img.cols)
					continue;
				if((rect[i].left+rect[i].width)>=img.rows)
					continue;
				img(m_rect).copyTo(ROI);
				fprintf(fid,"%s ",stemp.c_str());
                                fprintf(fid,"%d %d %d %d ",rect[i].left,rect[i].top,rect[i].width,rect[i].height);
				fprintf(fid,"%d\n",n);
			}
		

		}
		delete[]  rect;
		rect = NULL;
	}
	
	
	


	FGV_Destroy(handle);

	fclose(fid);
	return 0;
}




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值