Esempio n. 1
0
const char* rho_barcode_barcode_recognize(const char* filename) {
  void* img_buf = 0;
  int img_width;
  int img_height;	

  	
  rho_platform_image_load_grayscale(filename, &img_buf, &img_width, &img_height);

  if (img_buf != 0)
  {
	zbar_image_scanner_t* zbar_img_scanner = zbar_image_scanner_create();
	zbar_image_t* zbar_img = zbar_image_create();
	const zbar_symbol_t* zbar_symbol = 0;

        zbar_image_scanner_set_config(zbar_img_scanner, ZBAR_NONE, ZBAR_CFG_ENABLE, 1);

	zbar_image_set_format(zbar_img, zbar_fourcc('Y','8','0','0'));
	zbar_image_set_size(zbar_img, img_width, img_height);
	//zbar_image_set_data(zbar_img, img_buf, img_width * img_height, zbar_image_free_data);
	zbar_image_set_data(zbar_img, img_buf, img_width * img_height, 0);
		
	zbar_scan_image(zbar_img_scanner, zbar_img);

	
	// get result
	//zbar_symbol_set_t* zbar_symbols = zbar_image_get_symbols(zbar_img);
	zbar_symbol = zbar_image_first_symbol(zbar_img);

	if (zbar_symbol != 0) {
		//printf(zbar_symbol_get_data(zbar_symbol));
             //sprintf(strbuf, "IMG [%d x %d ]\nCODE = %s",img_width, img_height, zbar_symbol_get_data(zbar_symbol)); 
             strcpy(strbuf, zbar_symbol_get_data(zbar_symbol));
	}
        else {
             //sprintf(strbuf, "IMG [%d x %d ]\nCODE IS UNRECOGNIZED ",img_width, img_height); 
             strcpy(strbuf, "");
        }


	zbar_image_destroy(zbar_img);
	zbar_image_scanner_destroy(zbar_img_scanner);

  }
  else {
		//sprintf(strbuf, "NO IMG TO RECOGNIZE",img_width, img_height); 
        strcpy(strbuf, "");
  }

  if (img_buf) {
    rho_platform_image_free(img_buf);
  }
	  

  return strbuf;
}
Esempio n. 2
0
static void qr_detect_init()
{
    zscn = zbar_image_scanner_create();
    zbar_image_scanner_set_config(zscn, 0, ZBAR_CFG_ENABLE, 1);
    zbar_image_scanner_set_config(zscn, 0, ZBAR_CFG_X_DENSITY, 1);
    zbar_image_scanner_set_config(zscn, 0, ZBAR_CFG_Y_DENSITY, 1);

    zimg = zbar_image_create();
    zbar_image_set_size(zimg, 640, 360);
    zbar_image_set_format(zimg, zbar_fourcc('G','R','E','Y'));
}
Esempio n. 3
0
static int scan_image (const char *filename)
{
    if(exit_code == 3)
        return(-1);

    int found = 0;
    MagickWand *images = NewMagickWand();
    if(!MagickReadImage(images, filename) && dump_error(images))
        return(-1);

    unsigned seq, n = MagickGetNumberImages(images);
    for(seq = 0; seq < n; seq++) {
        if(exit_code == 3)
            return(-1);

        if(!MagickSetIteratorIndex(images, seq) && dump_error(images))
            return(-1);

        zbar_image_t *zimage = zbar_image_create();
        assert(zimage);
        zbar_image_set_format(zimage, zbar_fourcc('Y','8','0','0'));

        int width = MagickGetImageWidth(images);
        int height = MagickGetImageHeight(images);
        zbar_image_set_size(zimage, width, height);

        // extract grayscale image pixels
        // FIXME color!! ...preserve most color w/422P
        // (but only if it's a color image)
        size_t bloblen = width * height;
        unsigned char *blob = malloc(bloblen);
        zbar_image_set_data(zimage, blob, bloblen, zbar_image_free_data);

        if(!MagickExportImagePixels(images, 0, 0, width, height,
                                    "I", CharPixel, blob))
            return(-1);

        if(xmllvl == 1) {
            xmllvl++;
            printf("<source href='%s'>\n", filename);
        }

        zbar_process_image(processor, zimage);

        // output result data
        const zbar_symbol_t *sym = zbar_image_first_symbol(zimage);
        for(; sym; sym = zbar_symbol_next(sym)) {
            zbar_symbol_type_t typ = zbar_symbol_get_type(sym);
            unsigned len = zbar_symbol_get_data_length(sym);
            if(typ == ZBAR_PARTIAL)
                continue;
            else if(xmllvl <= 0) {
                if(!xmllvl)
                    printf("%s:", zbar_get_symbol_name(typ));
                if(len &&
                   fwrite(zbar_symbol_get_data(sym), len, 1, stdout) != 1) {
                    exit_code = 1;
                    return(-1);
                }
            }
            else {
                if(xmllvl < 3) {
                    xmllvl++;
                    printf("<index num='%u'>\n", seq);
                }
                zbar_symbol_xml(sym, &xmlbuf, &xmlbuflen);
                if(fwrite(xmlbuf, xmlbuflen, 1, stdout) != 1) {
                    exit_code = 1;
                    return(-1);
                }
            }
            printf("\n");
            found++;
            num_symbols++;
        }
        if(xmllvl > 2) {
            xmllvl--;
            printf("</index>\n");
        }
        fflush(stdout);

        zbar_image_destroy(zimage);

        num_images++;
        if(zbar_processor_is_visible(processor)) {
            int rc = zbar_processor_user_wait(processor, -1);
            if(rc < 0 || rc == 'q' || rc == 'Q')
                exit_code = 3;
        }
    }

    if(xmllvl > 1) {
        xmllvl--;
        printf("</source>\n");
    }

    if(!found)
        notfound++;

    DestroyMagickWand(images);
    return(0);
}
Esempio n. 4
0
static inline int
test_processor ()
{
    // create processor w/no video and no window
    zbar::Processor proc(debug, NULL);
    Handler handler;
    proc.set_handler(handler);
    if(debug) {
        proc.set_visible();
        proc.user_wait();
    }

    // generate barcode test image
    zbar::Image rgb3(0, 0, "RGB3");

    // test cast to C image
    if(test_image_ean13(rgb3))
        error("failed to generate image");

    // test decode
    expect(zbar::ZBAR_EAN13, test_image_ean13_data);
    proc.process_image(rgb3);
    if(debug)
        proc.user_wait();

    expect(zbar::ZBAR_EAN13, test_image_ean13_data);
    check_image(rgb3);

    if(rgb3.get_format() != zbar_fourcc('R','G','B','3'))
        error("image format mismatch");

    expect(zbar::ZBAR_NONE, "");
    proc.set_config(zbar::ZBAR_EAN13,
                    zbar::ZBAR_CFG_ENABLE,
                    false);
    proc.process_image(rgb3);
    check_image(rgb3);
    if(debug)
        proc.user_wait();

    proc.set_config("ean13.en");
    expect(zbar::ZBAR_EAN13, test_image_ean13_data);
    proc << rgb3;
    expect(zbar::ZBAR_EAN13, test_image_ean13_data);
    check_image(rgb3);
    if(debug)
        proc.user_wait();

    {
        zbar::Image grey(rgb3.convert(zbar_fourcc('G','R','E','Y')));
        expect(zbar::ZBAR_EAN13, test_image_ean13_data);
        proc << grey;

        zbar::Image y800 = grey.convert("Y800");
        expect(zbar::ZBAR_EAN13, test_image_ean13_data);
        proc << y800;
    }
    if(debug)
        // check image data retention
        proc.user_wait();

    expect(zbar::ZBAR_NONE, "");
    return(0);
}