main(int argc,char *argv[]) { FILE *f1; int f; f1=fopen(argv[1],"rb"); if(f1==NULL) return(0); fread(&header,sizeof(header),1,f1); lw=header.heigth; /**/ _asm mov ax,13h _asm int 10h saveframe(-1); for(f=0;f<header.frames;f++) { doframe(f1); saveframe(f); } saveframe(-2); /**/ fclose(f1); return(0); }
void* thread_acq_image(void*) { timespec time_save0, time_save1, t_sleep, t_rem; t_sleep.tv_sec = 0; t_sleep.tv_nsec = 10; dc1394video_frame_t *frame; for (;;) { /* wait for image */ pthread_mutex_lock( &camera_mutex ); int ret = gCamera.wait_for_image(1); pthread_mutex_unlock( &camera_mutex ); if (ret) { pthread_mutex_lock( &camera_mutex ); dc1394error_t err = dc1394_capture_dequeue(gCamera.cam(), DC1394_CAPTURE_POLICY_POLL, &frame); /* frame->timestamp appears to be broken, so we have to resort to clock_gettime */ timespec fts; clock_gettime( CLOCK_REALTIME, &fts ); double ft = t2d(fts); pthread_mutex_unlock( &camera_mutex ); if (err) { cleanup_and_exit(gCamera); std::cerr << dc1394_error_get_string(err) << "\nCould not capture frame" << std::endl; } // return frame to ring buffer: // if (frame->image) { pthread_mutex_lock( &camera_mutex ); err = dc1394_capture_enqueue(gCamera.cam(), frame); pthread_mutex_unlock( &camera_mutex ); if (err) { std::cerr << dc1394_error_get_string(err) << "\nCould not return frame to ring buffer" << std::endl; cleanup_and_exit(gCamera); } // } int width = frame->size[0]; int height = frame->size[1]; pthread_mutex_lock( &acq_buffer_mutex ); acq_frame_buffer.push(saveframe(std::vector<unsigned char>(&(frame->image)[0], &(frame->image)[width*height]), width, height, ft)); // (double)frame->timestamp)); pthread_mutex_unlock( &acq_buffer_mutex ); } else { nanosleep(&t_sleep, &t_rem); } } }
int get_image(cv::Mat& im, const cv::Mat& mapping, bool rotate, int socket, const std::string& fname, int& ncount) { int nframes = 0; /* empty the acquired frame buffer */ while (acq_frame_buffer.size() > 0) { int width = acq_frame_buffer.front().width; int height = acq_frame_buffer.front().height; double timestamp = acq_frame_buffer.front().timestamp; #ifndef LICKOMETER if (fname != "") { std::ostringstream jpgname; jpgname << fname << std::setfill('0') << std::setw(7) << ncount << ".jpg"; pthread_mutex_lock( &save_buffer_mutex ); save_frame_buffer.push(saveframe(acq_frame_buffer.front().data, width, height, timestamp, jpgname.str())); pthread_mutex_unlock( &save_buffer_mutex ); } #endif pthread_mutex_lock( &acq_buffer_mutex ); im = cv::Mat(cv::Size(width, height), CV_8UC1, &acq_frame_buffer.front().data[0]).clone(); if (rotate) { cv::Mat cpim = im.clone(); cv::warpAffine(cpim, im, mapping, im.size()); } acq_frame_buffer.pop(); pthread_mutex_unlock( &acq_buffer_mutex ); if (fname != "") { write_send(socket, timestamp, fname, ncount); } nframes++; } return nframes; }