Пример #1
0
int main(){
    VideoDevice camera;
    camera.startCapture(0);
    Mat img = camera.getImage();
    TargetDetector detector;
    Target* tar = detector.processImage(img);
    std::cout<<"yay no errors";
}
Пример #2
0
int main(int argc, char* argv[])
{
    // Create all the necessary objects (calls the default constructor for each)
    TargetDetector detector;
    TargetProcessor processor;
    NetworkController networkController;
    VideoDevice camera;
	CmdLineInterface interface(argc, argv);		
	AppConfig config = interface.getConfig();
	GUIManager gui;

	if(config.getIsDevice())
    {
        camera.startCapture(config.getDeviceID());
        if(config.getIsDebug())
            std::cout << "Camera ready!\n";
    }

    //init networking
    if(config.getIsNetworking())
        networkController.startServer();

    if(!config.getIsHeadless())
        gui.init();
    if(config.getIsDebug())
	 std::cout << "Im debugging! :D\n";

    while(true)
    {
        networkController.waitForPing();

        cv::Mat image = camera.getImage();
        Target* target = detector.processImage(image);

        bool foundTarget = (target == NULL ? false : true);

        if(foundTarget)
        {
            processor.loadTarget(target);
            double distance = processor.calculateDistance();

            networkController.sendMessage("true;" +
                boost::lexical_cast<std::string> (distance));

            std::cout << "Target Found! Distance: " << distance;
        }
        else
        {
            networkController.sendMessage("false;");
        }
    }

    return 0;
}
Пример #3
0
void RecordVideo::config_update()
{
	VideoDevice *vdevice = record->vdevice;
	vdevice->config_update();
	int width = vdevice->get_iwidth();
	int height = vdevice->get_iheight();
	double frame_rate = vdevice->get_irate();
	float awidth, aheight;
	MWindow::create_aspect_ratio(awidth, aheight, width, height);
	EDLSession *session = record->edl->session;
	SESSION->aspect_w = session->aspect_w = awidth;
	SESSION->aspect_h = session->aspect_h = aheight;
	SESSION->output_w = session->output_w = width;
	SESSION->output_h = session->output_h = height;
	Asset *rf_asset = SESSION->recording_format;
	Asset *df_asset = record->default_asset;
	rf_asset->width  = df_asset->width  = width;
	rf_asset->height = df_asset->height = height;
	rf_asset->frame_rate = df_asset->frame_rate = frame_rate;
}
Пример #4
0
int main(int argc, char* argv[])
{
    // get command line interface config options
    CmdLineInterface interface(argc, argv);
    AppConfig config = interface.getConfig();

    GUIManager gui;
    VideoDevice camera;
    LProcessor processor;
    NetworkController networkController;
    ArduinoController arduino;

    //init camera
    if(config.getIsDevice())
    {
        camera.startCapture(config.getDeviceID());
        if(config.getIsDebug())
            std::cout << "Camera ready!\n";
    }

    //init networking
    if(config.getIsNetworking())
        networkController.startServer();

    if(!config.getIsHeadless())
        gui.init();

    if (config.getHasArduino())
    {
        //16 is /dev/ttyUSB0, 24 is /dev/ttyACM0
        arduino.init(9600, 24);  //baud rate, serial port
    }
    //continuous server loop
    do
    {
        if(config.getIsNetworking())
            networkController.waitForPing();

        LDetector detector;

        cv::Mat image;
        if(config.getIsFile());
            //image = cv::imread(config.getFileName());
        //else
        //    image = camera.getImage(config.getIsDebug());

        //detector.elLoad(image);
        //detector.elSplit();
        //detector.elThresh();
        //detector.elContours(); detector.elFilter();

        bool foundL = true;
        if (detector.getLs().size() > 0)
            detector.largest2();
        else
            foundL = false;
        if (detector.getLs().size() == 0)
            foundL = false;
        if (foundL)
        {
            processor.determineL(detector.getLs());
            processor.determineAzimuth();
            processor.determineDistance();
            double azimuth = processor.getAzimuth();
            double distance = processor.getDistance();

            if(config.getIsDebug())
            {
                processor.outputData();
                std::cout << "Final distance (m): " << processor.getDistance() << std::endl;
            }

            if(!config.getIsHeadless())
            {
                int i_dist = (int) (distance * 1000.0);
                int dist_left = i_dist / 1000;
                int dist_right = i_dist % 1000;
                std::string dist_str = boost::lexical_cast<std::string>(dist_left) + "." + boost::lexical_cast<std::string>(dist_right);

                gui.setImage(detector.show());
                gui.setImageText("Distance: " + dist_str + " m");
                gui.show(config.getIsFile());
            }

            if(config.getIsNetworking())
            {
                networkController.sendMessage(boost::lexical_cast<std::string> ("true") + std::string(";")
                                              + boost::lexical_cast<std::string> (distance) + std::string(";")
                                              + boost::lexical_cast<std::string> (azimuth));
            }

        }
        else
        {
            if(config.getIsNetworking())
                networkController.sendMessage(boost::lexical_cast<std::string> ("false") + std::string(";"));
            if(!config.getIsHeadless())
            {
                gui.setImage(detector.show());
                gui.setImageText("No L's Found");
                gui.show(config.getIsFile());
            }
        }

        if(config.getHasArduino())
        {
            char c = std::rand() % 26 + 'A';
            arduino.sendMessage(c, cv::Point(5, 5));
            cv::waitKey(300);
        }

    }
    while(config.getIsDevice());

    return 0;
}
Пример #5
0
void RecordVideo::run()
{
// Number of frames for user to know about.
	gui->reset_video();

// Wait for trigger
	trigger_lock->lock("RecordVideo::run");

	while( !done && !write_result ) {
		if( recording_paused ) {
			pause_record_lock->unlock();
			record_paused_lock->lock();
		}
		if( done ) break;
		VideoDevice *vdevice = record->vdevice;
		VFrame *capture_frame = get_buffer();
		vdevice->set_field_order(record->reverse_interlace);
// Capture a frame
		grab_result = read_buffer(capture_frame);
		if( done ) break;
		if( vdevice->config_updated() ) {
			flush_buffer();
			delete_buffer();
			config_update();
			gui->reset_video();
			record->record_monitor->reconfig();
			continue;
		}
		if( grab_result ) {
			Timer::delay(250);
			continue;
		}
		decompress_buffer(capture_frame);
		record->resync();
		write_buffer();
		if( record->monitor_video && capture_frame->get_data() )
			if( !writing_file || !record->is_behind() )
				record->record_monitor->update(capture_frame);
		if( writing_file && record->fill_underrun_frames ) {
			VFrame *last_frame = capture_frame;
			int fill = record->dropped;
			while( --fill >= 0 ) {
				capture_frame = get_buffer();
				capture_frame->copy_from(last_frame);
				last_frame = capture_frame;
				write_buffer();
			}
		}
		else
			record->written_frames += record->dropped;
		if( record->single_frame ) {
			record->single_frame = 0;
			record->stop_writing_file();
		}
		if( done ) break;
		if( !done ) done = write_result;
		if( done ) break;
		record->check_batch_complete();
	}

SET_TRACE
	flush_buffer();
	delete_buffer();
SET_TRACE
//TRACE("RecordVideo::run 2");
	if( write_result ) {
		ErrorBox error_box(PROGRAM_NAME ": Error",
			mwindow->gui->get_abs_cursor_x(1),
			mwindow->gui->get_abs_cursor_y(1));
			error_box.create_objects(_("No space left on disk."));
		error_box.run_window();
	}
SET_TRACE
}
Пример #6
0
int main(int argc, char* argv[])
{
    // Create all the necessary objects (calls the default constructor for each)
    TargetDetector detector;
    TargetProcessor processor;
    NetworkController networkController;
    VideoDevice camera;
	CmdLineInterface interface(argc, argv);
	AppConfig config = interface.getConfig();
	//GUIManager gui;

	if(config.getIsDevice()){
        camera.startCapture(config.getDeviceID());
        if(config.getIsDebug())
            std::cout << "Camera ready!\n";
    }

    //init networking
    if(config.getIsNetworking())
        networkController.startServer();

    //if(!config.getIsHeadless())
    //    gui.init();
    if(config.getIsDebug())
	 	std::cout << "Im debugging! :D\n";
    cv::Mat image;

    //debug
    int loop = 1;
    cv::namedWindow("Live Video Feed", cv::WINDOW_NORMAL);
    cv::namedWindow("General", cv::WINDOW_NORMAL);


    while(cv::waitKey(30) != 27)
    {
        Mat background(Size(1000,1000), CV_8UC1, Scalar(255, 255, 255 ));

        if(config.getIsDebug())
            std::cout << "While Loop #" << loop << std::endl;

		if(config.getIsNetworking())
        	networkController.waitForPing();

        image = camera.getImage();
        if(!image.data) // check if image is valid
        {
            if(config.getIsDebug())
                std::cout << "failed to read image" << std::endl;
            return -1;
        }

        if(config.getIsDebug())
            std::cout << "Image Read" << std::endl;
        Target* target = detector.processImage(image);

        if(config.getIsDebug())
            std::cout << "Image Processed by Target Detector" << std::endl;
        /*
        (std::cout << "Target Value:" << target << "End of Target Value\n";
        std::cout << "CR A OW: " << target-> crow;
        target -> printPoints();
        */
        bool foundTarget = false;
        if (target != NULL)
        {
            foundTarget = true;
            image = detector.getOutlinedImage();
        }
        std::cout <<"About to check the value of foundTarget" << std::endl;
        if(foundTarget)
        {


            std::cout <<"Target was found " << std::endl;

            if(config.getIsDebug())
                std::cout << "Image Being Processed" << std::endl;

            processor.loadTarget(target);

            if(config.getIsDebug())
                std::cout << "Target Loaded" << std::endl;

            double distance = processor.calculateDistance();

            if(config.getIsDebug())
                std::cout << "Distance Calculated" << std::endl;

			double azimuth = processor.calculateAzimuth();
            if(config.getIsDebug())
                std::cout << "Azimuth Calculated" << std::endl;

			double altitude = processor.calculateAltitude();
            if(config.getIsDebug())
                std::cout << "Altitude Calculated" << std::endl;

            if(config.getIsDebug())
                std::cout << "Image Processed by TargetProcessor" << std::endl;

                std::string dis = "distance: " + std::to_string(distance);
                std::string alt = "altitude: " + std::to_string(altitude);
                std::string azi = "azimuth: " + std::to_string(azimuth);  

                cv::putText(background, dis, cv::Point(50,100),
                cv::FONT_HERSHEY_COMPLEX_SMALL, 2, cv::Scalar(0, 255, 0),
                1);

                cv::putText(background, alt, cv::Point(50,200),
                cv::FONT_HERSHEY_COMPLEX_SMALL, 2, cv::Scalar(0, 255, 0),
                1);

                cv::putText(background, azi, cv::Point(50,400),
                cv::FONT_HERSHEY_COMPLEX_SMALL, 2, cv::Scalar(0, 255, 0),
                1);

                imshow("General", background);

                if (config.getIsNetworking())
			    {
		            networkController.sendMessage("true;" +
		            boost::lexical_cast<std::string> (distance) + ";" +
					boost::lexical_cast<std::string> (azimuth) + ";" +
					boost::lexical_cast<std::string> (altitude));
			}

			if(config.getIsDebug()){
            	std::cout << "Target Found! Distance: " << distance;
                std::cout << "Altitude: " << altitude << std::endl;
                std::cout << "Azimuth: " << azimuth << std::endl;
            }

        }
        else
        {
            if (config.getIsNetworking())
                networkController.sendMessage("false;");
        }
        imshow("Live Video Feed", image);


        loop++;
        delete target;
    }

    return 0;
}