Json_Nie的专栏

一个自卑但又坚信勤能补拙的菜鸟

纯无聊贴(庆祝清明)

#include <fstream>
#include <string>
#include <cv.h>
#include <highgui.h>
#include <ml.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "cvaux.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

using namespace std;
using namespace cv;


const static Scalar colors[] =  { CV_RGB(0,0,255),
        CV_RGB(0,128,255),
        CV_RGB(0,255,255),
        CV_RGB(0,255,0),
        CV_RGB(255,128,0),
        CV_RGB(255,255,0),
        CV_RGB(255,0,0),
        CV_RGB(255,0,255)} ;


char* ReadPictureFile(int i,char* str);
char* ReadFile();
IplImage* PanLable(ifstream &datefile,IplImage* image);
void main()
{
	CvCapture *capture;
	IplImage* image;
	ifstream datefile;
	char* str = ReadFile();
	datefile.open(str);
	//char* str2 = (char*)malloc(1024*sizeof(char));
	
	for(int i=0;i<300;i++)
	{
		//char* str = ReadFile(i);
		//datefile.open(str);
		char* str2 = (char*)malloc(1024*sizeof(char));
		char* strPicture = (char*)malloc(1024*sizeof(char));
		strPicture = ReadPictureFile(i,str2);
		//char* strPicture2 = "K:\\PETS\\S0_CC\\Crowd_PETS09\\S0\\City_Center\\Time_12-34\\View_007\\frame_0000.jpg";
		capture = cvCaptureFromFile(strPicture);
		image = cvQueryFrame(capture);
		image = PanLable(datefile,image);
		cvNamedWindow("PlayPicture",0);
		cvShowImage("PlayPicture",image);
		cvWaitKey(35);
		//cvReleaseCapture(&capture);
		//cvDestroyWindow("PlayPicture");
		//datefile.close();
		//free(str2);
		free(strPicture);
		//free(str2);
		cout<<i<<endl;
	}
	datefile.close();
	//free(str2);
	cvReleaseCapture(&capture);
	cvDestroyWindow("PlayPicture");
}

char* ReadPictureFile(int i,char* str)
{
	//sprintf(str,""
	char *strtemp1 = "K:\\PETS\\S0_CC\\Crowd_PETS09\\S0\\City_Center\\Time_12-34\\View_007\\frame_000";
	char *strtemp2 = "K:\\PETS\\S0_CC\\Crowd_PETS09\\S0\\City_Center\\Time_12-34\\View_007\\frame_00";
	char *strtemp3 = "K:\\PETS\\S0_CC\\Crowd_PETS09\\S0\\City_Center\\Time_12-34\\View_007\\frame_0";
	char *temp = ".jpg";
	//char *str =(char*)malloc(1024*sizeof(char));
	if(i<10)
	{
		sprintf(str,"%s%d%s",strtemp1,i,temp);
	}
	else if(i<100)
	{
		sprintf(str,"%s%d%s",strtemp2,i,temp);
	}
	else if(i<1000)
	{
		sprintf(str,"%s%d%s",strtemp3,i,temp);
	}
	return str;
}

char* ReadFile()
{
	char *str = "K:\\PETS\\S0_CC\\Crowd_PETS09\\S0\\City_Center\\Time_12-34\\View_007.txt";
	return str;
}

IplImage* PanLable(ifstream &datefile,IplImage* image)
{
	char seps[]=" ";
	char *token;
	char bb[10000];
	int x1,y1;
	int x2,y2;
	int number;

	datefile.getline(bb,1000);
	token  = strtok(bb,seps);
	number=atoi(token);
	token = strtok(NULL,seps);
	while(token!=NULL)
	{
		number=atoi(token);
		token = strtok(NULL,seps);
		x1 = number;
		number=atoi(token);
		token = strtok(NULL,seps);
		y1 = number;
		number=atoi(token);
		token = strtok(NULL,seps);
		x2 = number;
		number=atoi(token);
		token = strtok(NULL,seps);
		y2 = number;
		cvRectangle(image,cvPoint(x1,y1),cvPoint(x2,y2),cvScalar(255,0,0),1);
	}
	return image;
}


阅读更多
个人分类: OpenCv
上一篇在windows下训练models of Object Detection with Discriminatively Trained Part Based Models
下一篇Part Based Models demo程序分析
想对作者说点什么? 我来说一句

开贴庆祝

开贴庆祝 

zjilin zjilin

2008-02-27 10:41:00

阅读数:155

没有更多推荐了,返回首页

关闭
关闭