[历史归档]本文原发布于 cstriker1407.info 个人博客,内容为历史存档,仅供参考。
发布时间:2017-11-12| 标题:交叉编译libzbar和libjpeg的简单笔记|分类:编程 / C && C++ |标签:C&&C++·zbar·libjpeg
交叉编译libzbar和libjpeg的简单笔记
- zbar
- 正常编译
- 交叉编译
- libjpeg
- 正常编译
- 交叉编译
- DEMO
最近项目上需要使用二维码识别,网上简单的搜索了下相关知识,这里简单的笔记下流水账。
zbar
首先下载zbar源码,官方网址:
解压后发现是configure这种方式编译的。
正常编译
cstriker1407:/zbar/zbar-0.10$ ./configure--help`configure' configures zbar0.10to adapt to many kinds of systems. 。。。。。。 。。。。。。 Report bugs to<spadix@users.sourceforge.net>.由于项目只用于识别二维码,因此简单起见,去掉所有的编译可选项。
cstriker1407:/zbar/zbar-0.10$ ./configure --disable-video --without-imagemagick --without-xv --without-xshm --without-gtk --without-python -without-qt --disable-assert 。。。。。。。。 。。。。。。。。 cstriker1407:/zbar/zbar-0.10$make。。。。。。。。 。。。。。。。。编译完成后的库就在 zbar/.libs/ 中。
交叉编译
cstriker1407:/zbar/zbar-0.10$CC=XXXXXXXX/bin/arm-unknown-linux-uclibcgnueabi-gcc ./configure --disable-video --without-imagemagick --without-xv --without-xshm --without-gtk --without-python -without-qt --disable-assert--build=x86_64-host=arm-unknown-linux-uclibcgnueabi --disable-shared cstriker1407:/zbar/zbar-0.10$makelibjpeg
libjpeg的下载地址
【 https://sourceforge.net/projects/libjpeg/ 】
正常编译
cstriker1407:/libjpeg/jpeg-9b$ ./configure cstriker1407:/libjpeg/jpeg-9b$make交叉编译
cstriker1407:/libjpeg/jpeg-9b$CC=usr/bin/arm-unknown-linux-uclibcgnueabi-gcc ./configure--build=x86_64-host=arm-unknown-linux-uclibcgnueabi cstriker1407:/libjpeg/jpeg-9b$makeDEMO
#include<stdio.h>#include<stdlib.h>#include<stdio.h>#include<string.h>#include<unistd.h>#include<zbar.h>#include<jpeglib.h>#include<jerror.h>staticvoid_convert_data(constunsignedchar*p_jpg_buffer,unsignedintjpg_size,int*width,int*height,void**raw){structjpeg_decompress_structcinfo;structjpeg_error_mgrerr;cinfo.err=jpeg_std_error(&err);jpeg_create_decompress(&cinfo);jpeg_mem_src(&cinfo,(unsignedchar*)p_jpg_buffer,jpg_size);(void)jpeg_read_header(&cinfo,TRUE);cinfo.out_color_space=JCS_GRAYSCALE;// cinfo.two_pass_quantize = TRUE;(void)jpeg_start_decompress(&cinfo);*width=cinfo.image_width;*height=cinfo.image_height;*raw=(void*)malloc(cinfo.output_width*cinfo.output_height*3);unsignedbpl=cinfo.output_width*cinfo.output_components;JSAMPROW buf=(void*)*raw;JSAMPARRAY line=&buf;for(;cinfo.output_scanline<cinfo.output_height;buf+=bpl){jpeg_read_scanlines(&cinfo,line,1);}(void)jpeg_finish_decompress(&cinfo);jpeg_destroy_decompress(&cinfo);}intmain(intargc,char**argv){if(argc<2)return(1);FILE*pFile=fopen(argv[1],"r+b");unsignedchar*p_ReadBuffer=malloc(81920);memset(p_ReadBuffer,0,81920);intfreadResult=fread(p_ReadBuffer,1,81920,pFile);printf("read%d ",freadResult);zbar_image_scanner_t*scanner=NULL;scanner=zbar_image_scanner_create();zbar_image_scanner_set_config(scanner,ZBAR_QRCODE,ZBAR_CFG_ENABLE,1);/* obtain image data */intwidth=0,height=0;void*raw=NULL;_convert_data(p_ReadBuffer,freadResult,&width,&height,&raw);free(p_ReadBuffer);printf("width:%d height:%d ",width,height);/* wrap image data */zbar_image_t*image=zbar_image_create();zbar_image_set_format(image,*(int*)"Y800");zbar_image_set_size(image,width,height);zbar_image_set_data(image,raw,width*height,zbar_image_free_data);/* scan the image for barcodes */intn=zbar_scan_image(scanner,image);/* extract results */constzbar_symbol_t*symbol=zbar_image_first_symbol(image);for(;symbol;symbol=zbar_symbol_next(symbol)){/* do something useful with results */zbar_symbol_type_ttyp=zbar_symbol_get_type(symbol);constchar*data=zbar_symbol_get_data(symbol);printf("decoded%s symbol \"%s\" ",zbar_get_symbol_name(typ),data);}/* clean up */zbar_image_destroy(image);zbar_image_scanner_destroy(scanner);return0;}