コード例 #1
0
ファイル: genprotolive.c プロジェクト: ChristianFrisson/XKin
int main (int argc, char *argv[])
{
	CvHMM *models;
	char *win = "hand";
	int num, count=0, curr=1; 
	ptseq seq;
	
	parse_args(argc,argv);
	seq = ptseq_init();
	
	for (;;) {
		IplImage *depth, *tmp, *body, *hand;
		CvSeq *cnt;
		CvPoint cent;
		int z, p, k; 
		
		depth = freenect_sync_get_depth_cv(0);
		body = body_detection(depth);
		hand = hand_detection(body, &z);
		
		if (!get_hand_contour_basic(hand, &cnt, &cent))
			continue;
		
		if ((p = basic_posture_classification(cnt)) == -1)
			continue;
		
		if (cvhmm_get_gesture_sequence(p, cent, &seq)) {
			ptseq_draw(seq, 0);
			if ((k = cvWaitKey(0)) == 's') {
				save_sequence(outfile, seq, N);
				break;
			}
			seq = ptseq_reset(seq);
		}
		
		hand = draw_depth_hand(cnt, p);
		cvShowImage("hand", hand);

		if ((k = cvWaitKey(T)) == 'q')
			break;
	}

	freenect_sync_stop();
	cvDestroyAllWindows();

	return 0;
}
コード例 #2
0
FunctionMode ImageAnalysis::area_detection(Tracker *tracker)
{
	/* Too small values lead to flawed detections. We backup the 
	 * user value and restore it later. */
	int backupMinBlobSize = m_pSettingKinect->m_kinectProp.minBlobArea;

	switch (m_area_detection_step) {
	case 2:
		{// Wait util no blob is detected.
			//printf("area detection 2\n");
			hand_detection();
			m_pSettingKinect->m_kinectProp.minBlobArea = max(backupMinBlobSize,256);
			tracker->trackBlobs(m_filteredMat(m_pSettingKinect->m_kinectProp.roi), m_areaMask, true, NULL);
			m_pSettingKinect->m_kinectProp.minBlobArea = backupMinBlobSize;
			if( tracker->getBlobs().size() == 0 ){
				m_area_detection_step = 1;
			}
		} break;
	case 3://for AREA_DETECTION_END
		{
			//printf("area detection 3\n");
			m_area_detection_step = 3;
			repoke_finish();
			return HAND_DETECTION;
		} break;
	case 0:
		{
			printf("area detection 0\n");
			repoke_init();
			genColoredAreas();
			m_area_detection_step = 1;
		}//no break!
	case 1:
		{
			//printf("area detection 1\n");
			//Mat& depth = m_depthMaskWithoutThresh;
			hand_detection();
			m_pSettingKinect->m_kinectProp.minBlobArea = max(backupMinBlobSize,256);
			tracker->trackBlobs(m_filteredMat(m_pSettingKinect->m_kinectProp.roi), m_areaMask, true, NULL);
			m_pSettingKinect->m_kinectProp.minBlobArea = backupMinBlobSize;
			std::vector<cBlob>& blobs = tracker->getBlobs();

			for(int i=0;i<blobs.size(); i++){
				if( blobs[i].event != BLOB_MOVE) continue;
				if( blobs[i].areaid == 1 ){
					/* detection finshed. */
					m_area_detection_step = 0;

					//reset pixels with MAXAREAS+1 value
					repoke_finish();
					//clear blobs to begin fresh in hand detection.
					blobs.clear();
					return HAND_DETECTION;
				}
			}
			for(int i=0;i<blobs.size(); i++){
				if( blobs[i].event != BLOB_MOVE) continue;
				if( blobs[i].areaid == MAXAREAS+1 ){
					//found new blob without area
					Area area;
					area.id = m_area_detection_areas.size()+1;
					area.repoke_x = blobs[i].location.x+m_pSettingKinect->m_kinectProp.roi.x;
					area.repoke_y = blobs[i].location.y+m_pSettingKinect->m_kinectProp.roi.y;

					if( ! repoke_step(area) )
						return AREA_DETECTION;

					m_area_detection_step = 2;
					break;
				}
			}
		}break;
	default:
		{
			printf("Unknown state during area detection\n");
		}break;
	}

	return AREA_DETECTION;
}
コード例 #3
0
ファイル: trainposture.c プロジェクト: ChristianFrisson/XKin
int main (int argc, char *argv[])
{
	IplImage *rgb, *depth, *tmp, *body, *hand;
	CvMat **tr, *mean, *cov;
	CvFileStorage *fs;
	int count=0, p=0, warmup=1;

	parse_args(argc, argv);

	rgb = cvCreateImage(cvSize(W,H), 8, 3);
	tr = (CvMat**)malloc(sizeof(CvMat*)*num);
	init_training_data(tr,num);
	mean = cvCreateMat(1, FD_NUM, CV_64FC1);
	cov  = cvCreateMat(FD_NUM, FD_NUM, CV_64FC1);

	fs = cvOpenFileStorage(outfile, NULL, CV_STORAGE_WRITE, NULL);
	assert(fs);

	for (;;) {
		int z, k, c;
		CvMat *fd;
		CvSeq *cnt;
		
		tmp = freenect_sync_get_rgb_cv(0);
		cvCvtColor(tmp, rgb, CV_BGR2RGB);
		depth = freenect_sync_get_depth_cv(0);
		body = body_detection(depth);
		hand = hand_detection(body, &z);

		if (!get_hand_contour_advanced(hand, rgb, z, &cnt, NULL))
		 	continue; 

		if (warmup) {
			draw_contour(cnt);
			if (k = cvWaitKey(T) == 'g') {
				warmup = 0;
				cvDestroyAllWindows();
			}
			continue;
		}

		fd = get_fourier_descriptors(cnt);
		add_training_data(tr[count], fd);

		if (count == 0)
			printf("---> training hand pose %d\n", p);

		if (++count == num) {
			int c;

			cvCalcCovarMatrix((void*)tr, count, cov, mean, CV_COVAR_NORMAL);
			cvInvert(cov, cov, CV_LU);
			save_posture_model(fs, mean, cov);
			p++;
			count = 0;

			printf("save and quit:s  exit:q  next:any \n");
			
			if ((c = cvWaitKey(0)) == 's') {
				break;
			} else if (c == 'q') {
				break;
			} else {
				continue;
			}
		}

		draw_contour(cnt);
		cvWaitKey(T);
	}

	cvWriteInt(fs, "total", p);

	freenect_sync_stop();

	free_training_data(tr,num);
	cvReleaseFileStorage(&fs);
	cvReleaseMat(&mean);
	cvReleaseMat(&cov);
	cvReleaseImage(&rgb);

	return 0;
}