int main( int argc, char *argv[] ) { clock_t tStart = clock(); if(argc!=3) { printf("\n\nError : Change input in this form: %s file1.jpg file2.jpg \n\n",argv[0]); return -1; } char *infilename = argv[1], *outfilename = argv[2]; int x; if( read_jpeg_file(infilename) == 1 ) { printf("The image was read successfully. \n"); } if(write_jpeg_file(outfilename)==1) { printf("The jpeg file was filtered successfully. \n"); } printf("Time taken: %lf s\n", (double)(clock() - tStart)/CLOCKS_PER_SEC); return 0; }
/* * do the thing */ int main(int argc, char *argv[]) { int fd_main, fd_watermark, fd_out; int option; int x, y; x = 0; y = 0; while((option = getopt(argc, argv, "x:y:")) != -1) { switch(option) { case 'x': x = atoi(optarg); break; case 'y': y = atoi(optarg); break; default: fprintf(stderr, "Unknown option: %c", option); exit(EXIT_FAILURE); } } fd_main = open("in.jpg", O_RDONLY); fd_watermark = open("watermark.jpg", O_RDONLY); fd_out = open("out.jpg", O_WRONLY | O_CREAT, 0666); if((fd_main < 0) || (fd_watermark < 0) || (fd_out < 0)) { fprintf(stderr, "Error opening input/output files\n"); exit(EXIT_FAILURE); } image_data_t *main = read_jpeg_file(fd_main); if(!main) exit(EXIT_FAILURE); printf("Input file data:\n"); dump_jpeg_info(main); image_data_t *watermark = read_jpeg_file(fd_watermark); if(!watermark) exit(EXIT_FAILURE); printf("\nWatermark file data:\n"); dump_jpeg_info(watermark); blit_jpeg(main, watermark, x, y); write_jpeg_file(fd_out, main); close(fd_main); close(fd_watermark); close(fd_out); return 0; }
int main() { char *infilename = "test.jpg", *outfilename = "test_out.jpg"; /* Try opening a jpeg*/ if( read_jpeg_file( infilename ) > 0 ) { /* then copy it to another file */ if( write_jpeg_file( outfilename ) < 0 ) return -1; } else return -1; return 0; }
int main(int argc, char** argv) { unsigned char* img_sub = 0; unsigned char* img_normal = 0; unsigned char* img_supra = 0; unsigned char* img_hdr = 0; int w = 0, h = 0; unsigned long i, vect_size; if(argc < 5) { printf( "Usage: ./hdr img1.jpg img2.jpg img3.jpg imgfinal.jpg\n"); return 1; } read_jpeg_file(&img_sub, &h, &w, argv[1]); read_jpeg_file(&img_normal, &h, &w, argv[2]); read_jpeg_file(&img_supra, &h, &w, argv[3]); vect_size = w*h*3; struct timeval start, end; gettimeofday(&start, NULL); apply_tone_mapping(img_sub, vect_size); apply_tone_mapping(img_normal, vect_size); apply_tone_mapping(img_supra, vect_size); img_hdr = malloc(vect_size* sizeof(unsigned char)); for(i =0; i< vect_size; ++i) { int temp =0; temp += (int)img_sub[i]; temp += (int)img_normal[i]; temp += (int)img_supra[i]; img_hdr[i] = (char)(temp/3); } gettimeofday(&end, NULL); printf("Times: %lf\n", (float)(((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)))/1000000); write_jpeg_file(img_hdr, h,w, argv[4], 100); return 0; }
int main() { char *infilename = "pool.jpg", *outfilename = "test_out.jpg"; /* Try opening a jpeg*/ if( read_jpeg_file( infilename ) > 0 ) { filter_out_table(0, 100, 20, 255, 0, 100); /* then copy it to another file */ if( write_jpeg_file( outfilename ) < 0 ) return -1; } else return -1; return 0; }
int main(int argc, char *argv[]) { IplImage* img1, * img2, * stacked1, *stacked2; char stemp[1024]; // printf("Reading images: %s and %s\n",argv[1],argv[2]); if(argc != 3) {printf("\n\nUsage: getsift [image1.jpg] [image2.jpg]\n\n"); exit(0);} img1=read_jpeg_file(argv[1]); img2=read_jpeg_file(argv[2]); stacked1 = stack_imgs( img1, img2 ); stacked2 = stack_imgs( img1, img2 ); struct feature* feat1, * feat2, * feat; struct feature** nbrs; struct feature** RANnb; struct kd_node* kd_root; CvPoint pt1, pt2; double d0, d1; int n1, n2, k, i,j, m = 0, n=0; printf("SIFT Features Extraction: %s\n", argv[1]); n1 = sift_features( img1, &feat1 ); printf("Numbers of Features from %s: %d\n",argv[1], n1); printf("SIFT Features Extraction: %s\n", argv[2]); n2 = sift_features( img2, &feat2 ); printf("Numbers of Features from %s: %d\n",argv[2], n2); sprintf(stemp,"%s.sift.jpg",argv[1]); draw_keypoint( img1, feat1, n1 ); write_jpeg_file(stemp,img1); sprintf(stemp,"%s.sift.jpg",argv[2]); draw_keypoint( img2, feat2, n2 ); write_jpeg_file(stemp,img2); FILE * feat1file; FILE * feat2file; feat1file=fopen("features1.txt","w+"); for(i=0;i<n1;i++) { fprintf(feat1file,"(%lf,%lf): {",(feat1+i)->x,(feat1+i)->y); for(j=0;j<FEATURE_MAX_D;j++) fprintf(feat1file,"% lf ",(feat1+i)->descr[j]); fprintf(feat1file,"}\n"); } printf("coordinate and descriptor of %s keypoints have been written in featfile1.txt\n",argv[1]); feat2file=fopen("features2.txt","w+"); for(i=0;i<n2;i++) { fprintf(feat2file,"(%lf,%lf): {",(feat2+i)->x,(feat2+i)->y); for(j=0;j<FEATURE_MAX_D;j++) fprintf(feat2file,"% lf ",(feat2+i)->descr[j]); fprintf(feat2file,"}\n"); } printf("coordinate and descriptor of %s keypoints have been written in featfile2.txt\n",argv[2]); kd_root = kdtree_build( feat2, n2 ); for( i = 0; i < n1; i++ ) { feat = feat1 + i; k = kdtree_bbf_knn( kd_root, feat, 2, &nbrs, KDTREE_BBF_MAX_NN_CHKS ); if( k == 2 ) { d0 = descr_dist_sq( feat, nbrs[0] ); d1 = descr_dist_sq( feat, nbrs[1] ); if( d0 < d1 * NN_SQ_DIST_RATIO_THR ) { pt1 = cvPoint( cvRound( feat->x ), cvRound( feat->y ) ); pt2 = cvPoint( cvRound( nbrs[0]->x ), cvRound( nbrs[0]->y ) ); pt2.y += img1->height; cvLine( stacked1, pt1, pt2, CV_RGB(255,0,255), 1, 8, 0 ); m++; feat1[i].fwd_match = nbrs[0]; } } free( nbrs ); } printf("Found %d total matches\n", m ); write_jpeg_file("matches.jpg",stacked1); CvMat* H; int number=0; H = ransac_xform( feat1, n1, FEATURE_FWD_MATCH, lsq_homog, 4, 0.25, homog_xfer_err, 27.0, &RANnb, &number ); for( i = 0; i < number; i++ ) { pt1 = cvPoint( cvRound( RANnb[i]->x ), cvRound( RANnb[i]->y ) ); pt2 = cvPoint( cvRound( RANnb[i]->fwd_match->x ), cvRound( RANnb[i]->fwd_match->y ) ); pt2.y += img1->height; cvLine( stacked2, pt1, pt2, CV_RGB(255,0,255), 1, 8, 0 ); n++; } printf("Found %d total matches after RANSAC\n", n ); write_jpeg_file("matches.ransac.jpg",stacked2); cvReleaseImage( &img1 ); cvReleaseImage( &img2 ); kdtree_release( kd_root ); free( feat1 ); free( feat2 ); return 0; }
int main(int argc,char **argv) { int ret; int numBufs = 0; unsigned char *buffer; /* * declaration for framebuffer device */ int fbdev; char *fb_device; unsigned char *fbmem; unsigned int screensize; unsigned int fb_width; unsigned int fb_height; unsigned int fb_depth; unsigned int x; unsigned int y; int fd; int nResult; struct InputData event; cam_fd = open("/dev/video0" ,O_RDWR); if(cam_fd < 0){ printf("can not open driver!! \n"); exit(1); } fd = open("/dev/input/event0", O_RDONLY|O_NONBLOCK); if(fd==-1) { perror("open(event0)"); return 1; } //设置帧格式 memset(&fmt,0,sizeof(fmt)); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; // 数据流类型,必须永远是V4L2_BUF_TYPE_VIDEO_CAPTURE fmt.fmt.pix.width = VIDEO_WIDTH; fmt.fmt.pix.height = VIDEO_HEIGHT; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB565; //要与摄像头相对应, 视频数据存储类型,例如是YUV4:2:2还是RGB fmt.fmt.pix.depth = 16; if(ioctl(cam_fd, VIDIOC_S_FMT,&fmt) < 0){ printf("set format is fail!! \n"); exit(4); } /* * open framebuffer device */ if ((fb_device = getenv("FRAMEBUFFER")) == NULL) fb_device = FB_DEV; fbdev = fb_open(fb_device); /* * get status of framebuffer device */ fb_stat(fbdev, &fb_width, &fb_height, &fb_depth); if ((VIDEO_WIDTH > fb_width) || (VIDEO_HEIGHT > fb_height)) return (-1); /* * map framebuffer device to shared memory */ screensize = fb_width * fb_height * fb_depth / 8; fbmem = fb_mmap(fbdev, screensize); /*以上步骤完成了视频采集的准备工作,但驱动还没有启动采集过程, 应用程序需要调用VIDIOC_STREAMON ioctl 系统调用驱动才会开始采集数据。 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; ioctl (fd, VIDIOC_STREAMON, &type);*/ //开始采集视频 int buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if(ioctl(cam_fd,VIDIOC_STREAMON,&buf_type) < 0){ printf("VIDIOC_STREAMON is fail!! \n"); exit(9); } /*采集过程开始以后,驱动会不停地将数据写入分配的缓冲区内, 当一个缓冲区的数据准备就绪后,驱动就会将其放入输出队列,等待应用程序的处理。 当所有的缓冲区都进入输出队列后,驱动将停止采集,并等待缓冲区重新放入采集队列。 读取数据时,首先需要将一个缓冲区出队列: struct v4l2_buffer buf; ioctl (fd, VIDIOC_DQBUF, &buf);*/ //取出FIFO 缓存中已经采样的帧缓存, int i = 0; while(i < 1000){ char* buffer = (char*) calloc(VIDEO_WIDTH * VIDEO_HEIGHT*2 ,1); int count = read(cam_fd,buffer,VIDEO_WIDTH * VIDEO_HEIGHT *2); printf(">> %d\n",count); for(y = 0;y < VIDEO_HEIGHT;y++){ memcpy(fbmem + y * fb_width * 2,buffer + y * VIDEO_WIDTH * 2,VIDEO_WIDTH * 2); } nResult = read(fd,&event,sizeof(event)); if(nResult==sizeof(event)){ printf("keycode:%d,keyvalue:%d\n",event.code,event.value); write_jpeg_file( "cemara.jpg"); break; } i++; } //停止视频的采集 if(ioctl(cam_fd,VIDIOC_STREAMOFF,&buf_type) < 0){ printf("VIDIOC_STREAMOFF is fail!! \n"); exit(12); } close(cam_fd); close(fbdev); close(fd); return 0; }
void process_data(rgb_ptr buf){ if (get_io_cfg()->do_save_image) write_jpeg_file(buf, 50); if (get_io_cfg()->do_send) send_jpeg_data(buf, 50); }