コード例 #1
0
/*
 * tests the distance() function
 */
void testDistance(){
	double result = imageProcessor.distance(cv::Point(100, 15), cv::Point(75, 36));
	assert(result < 32.64 + DELTA && result > 32.64 - DELTA);
	
	result = imageProcessor.distance(cv::Point(3, 5), cv::Point(9, 7));
	assert(result < 6.32 + DELTA && result > 6.32 - DELTA);

	result = imageProcessor.distance(cv::Point(572, 641), cv::Point(894, 127));
	assert(result < 606.53 + DELTA && result > 606.53 - DELTA);

	printf("distance() test passed.\n");
}
コード例 #2
0
ファイル: bot.cpp プロジェクト: cameroncros/RaspPiVision
int main(int argc, char **argv)
{
	if (argc != 2) {
		exit(1);
	}
	signal(SIGINT, intHandler);

	std::string arg = argv[1];
 	cv::VideoCapture capture(arg); //try to open string, this will attempt
        if (!capture.isOpened()) //if this fails, try to open as a video camera
                capture.open(atoi(arg.c_str()));
        if (!capture.isOpened()) {
                std::cerr << "Failed to open a video device or video file!\n" << std::endl;
                return 1;
        }

	ImageProcessor *ip = new HSV_Region_Processor_Min_Alloc(capture);
	BotController *bt = new BotController();
	Region *dp;
	cv::Mat frame;
	ip->initialiseWindow();
	std::vector<Region *> *regionList;
	while (keepRunning) {
		capture >> frame;
		ip->cleanRegionList();
		regionList = ip->processFrame(frame);
		std::sort(regionList->begin(), regionList->end(), compareBySize);
		dp = (*regionList)[0];
		if (dp != NULL && dp->getSize() > 100) {
			double angle = ip->angle(frame, *dp);
			double distance = ip->distance(frame, *dp);
			std::cout << angle << " - " << distance << std::endl;
			bt->move(angle, distance);
			ip->drawArrow(frame, angle, distance);

			//ip->saveFrame(frame);
		} else {
			std::cout << "No object found, sitting still" << std::endl;
			bt->stop();
		}
		ip->drawFrame(frame);
		cv::waitKey(5);
//		ip->processKeys(frame);
	}
	std::cout << "Shutting down" << std::endl;
	bt->stop();
}