示例#1
0
文件: ORF.cpp 项目: khobbs91/16.831
int main(void)
{
        printf("ORF pid %d\n", (int) getpid());
        SRCAM cam;
        // int ret = SR_OpenDlg(&cam, 2, 0); // 2: call open dialog, 0: no parent window
        // int ret = SR_OpenETH(&cam, "192.168.1.33");
        int ret = SR_OpenETH(&cam, "169.254.1.33");
        if(ret<=0) return -1; // ret holds the number of cameras found
        cv::Size imsize(SR_GetCols(cam), SR_GetRows(cam)); // SR image size
        int sizebytes = 2 * imsize.area() * sizeof(unsigned short); // number of bytes sent from the SR 
        // namedWindow("mainWin",WINDOW_AUTOSIZE );
        cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
        int sizestep = sizeof(float)*3; // size step from one xyz component to the next
        int c=-1; // user input variable
        // enable software trigger mode so that the LEDs will only turn
        // on when SR_Acquire() is called
        SR_SetMode(cam,AM_SW_TRIGGER);
        std::time_t start_time = std::time(0);
        while(c==-1) // infinite loop, breaks if key pressed
        {
                ret = SR_Acquire(cam);
                cv::Mat xyz(imsize, CV_32FC3, cv::Scalar::all(0));
                if(ret!=sizebytes) break;
                // the coordinates are stored as three channels in the format
                // (x1, y1, z1, x2, y2, z2, ... ) squentially row by row
                SR_CoordTrfFlt( cam,
                                &((float*)xyz.ptr())[0], // pointer to first x
                                &((float*)xyz.ptr())[1], // pointer to first y
                                &((float*)xyz.ptr())[2], // pointer to first z
                                sizestep, sizestep, sizestep); // increments to next element

                cv::Mat z, z_display; // z channel and output image
                extractImageCOI(&CvMat(xyz), z, 2); // extract the z channel (change the 2 for another channel)
                z.convertTo(z_display, CV_8UC1, 256.0 / 5.0, 0); // convert to 8 bit (0..255) values, here for 5 meter camera
                cv::imshow("mainWin", z_display); // display image
                std::time_t t = std::time() - start_time;
                printf("ORF data taken at %d seconds\n", t);
                //std::cout << "ORF data taken at" << t << "seconds\n";
                std::stringstream filename;
                filename << "./ORF_photos/" << t << ".bmp"
                cv::imwrite(filename.str(),z_display);
                c = cvWaitKey(1000); // wait 1 sec before continuing loop. if user presses a button, the loop will exit
        }
        SR_Close(cam);
        return 0;
}
示例#2
0
void mesa_grab_frame(mesa_t *frame) {
	assert(frame->distance != NULL);
	assert(frame->amplitude != NULL);
	assert(frame->confidence != NULL);
	// get images
	int r = SR_Acquire(_srcam);
	if (r < 0) {
		fprintf(stderr, "Error getting data from the camera: %d\n", r);
		mesa_close_device();
		exit(1);
	}

	frame->distance = (unsigned char*) SR_GetImage(_srcam, 0);
	frame->amplitude = (unsigned char*) SR_GetImage(_srcam, 1);
	frame->confidence = (unsigned char*) SR_GetImage(_srcam, 2);
	SR_CoordTrfFlt(_srcam, frame->x, frame->y, frame->z, sizeof(float),
			sizeof(float), sizeof(float));
}