int main (int argc, char **argv) { zbar_set_verbosity(32); zbar_processor_t *proc = zbar_processor_create(0); assert(proc); if(zbar_processor_init(proc, NULL, 1)) return(2); zbar_image_t *img = zbar_image_create(); zbar_image_set_size(img, 8, 8); zbar_image_set_format(img, fourcc('J','P','E','G')); zbar_image_set_data(img, jpeg, sizeof(jpeg), NULL); zbar_image_t *test = zbar_image_convert(img, fourcc('Y','8','0','0')); if(!test) return(2); printf("converted: %d x %d (%lx) %08lx\n", zbar_image_get_width(test), zbar_image_get_height(test), zbar_image_get_data_length(test), zbar_image_get_format(test)); if(zbar_process_image(proc, test) < 0) return(3); if(zbar_processor_set_visible(proc, 1)) return(4); zbar_processor_user_wait(proc, -1); return(0); }
JNIEXPORT void JNICALL Java_net_sourceforge_zbar_Image_setFormat (JNIEnv *env, jobject obj, jstring format) { uint32_t fourcc = format_to_fourcc(env, format); if(!fourcc) return; zbar_image_set_format(GET_PEER(Image, obj), fourcc); }
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; }
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')); }
static zbar_image_t *_php_zbarcode_image_create(unsigned long width, unsigned long height, unsigned char *image_data) { zbar_image_t *image = zbar_image_create(); if (!image) return NULL; zbar_image_set_format(image, *(int*)"Y800"); zbar_image_set_size(image, width, height); zbar_image_set_data(image, (void *)image_data, width * height, zbar_image_free_data); return image; }
JNIEXPORT jstring JNICALL Java_com_acdd_qrcode_BarCode_decodeCrop( JNIEnv *env,jclass clazz, jbyteArray img, jint width, jint height, jint x, jint y, jint cropw, jint croph) { zbar_image_scanner_t *scanner; zbar_image_t *zimage; zbar_image_t *zgrayimage; jbyte *pixbuf; jstring s = NULL; zbar_set_verbosity(10); // XXX pixbuf = (*env)->GetByteArrayElements(env, img, 0); zimage = zbar_image_create(); if (zimage == NULL) { (*env)->ReleaseByteArrayElements(env, img, pixbuf, 0); return NULL; } zbar_image_set_format(zimage, *(unsigned long *) "Y800"); zbar_image_set_size(zimage, width, height); zbar_image_set_data(zimage, pixbuf, (*env)->GetArrayLength(env, img), zbar_image_free_data); zbar_image_set_crop(zimage, x, y, cropw, croph); zgrayimage = zbar_image_convert(zimage, *(unsigned long *) "Y800"); if (zgrayimage == NULL) { (*env)->ReleaseByteArrayElements(env, img, pixbuf, 0); return NULL; } zbar_image_destroy(zimage); scanner = zbar_image_scanner_create(); zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1); zbar_scan_image(scanner, zgrayimage); const zbar_symbol_t *sym; sym = zbar_image_first_symbol(zgrayimage); if (sym != NULL) { const char *sym_data; sym_data = zbar_symbol_get_data(sym); __android_log_print(ANDROID_LOG_DEBUG, "zbar", "url: %s", sym_data); s = (*env)->NewStringUTF(env, sym_data); } (*env)->ReleaseByteArrayElements(env, img, pixbuf, 0); return s; }
JNIEXPORT jstring JNICALL Java_trikita_obsqr_Zbar_process (JNIEnv *env, jobject obj, jint w, jint h, jbyteArray img) { zbar_image_scanner_t *scanner; zbar_image_t *zimage; zbar_image_t *zgrayimage; jbyte *pixbuf; jstring s = NULL; zbar_set_verbosity(10); // XXX pixbuf = (*env)->GetByteArrayElements(env, img, 0); zimage = zbar_image_create(); if (zimage == NULL) { (*env)->ReleaseByteArrayElements(env, img, pixbuf, 0); return NULL; } zbar_image_set_format(zimage, *(unsigned long *) "Y800"); zbar_image_set_size(zimage, w, h); zbar_image_set_data(zimage, pixbuf, (*env)->GetArrayLength(env, img), zbar_image_free_data); zgrayimage = zbar_image_convert(zimage, *(unsigned long *) "Y800"); if (zgrayimage == NULL) { (*env)->ReleaseByteArrayElements(env, img, pixbuf, 0); return NULL; } zbar_image_destroy(zimage); scanner = zbar_image_scanner_create(); zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1); zbar_scan_image(scanner, zgrayimage); const zbar_symbol_t *sym; sym = zbar_image_first_symbol(zgrayimage); if (sym != NULL) { const char *sym_data; sym_data = zbar_symbol_get_data(sym); __android_log_print(ANDROID_LOG_DEBUG, "zbar", "url: %s", sym_data); s = (*env)->NewStringUTF(env, sym_data); } (*env)->ReleaseByteArrayElements(env, img, pixbuf, 0); return s; }
int main (int argc, const char *argv[]) { processor = zbar_processor_create(0); assert(processor); if(zbar_processor_init(processor, NULL, 0)) { zbar_processor_error_spew(processor, 0); return(1); } zbar_image_t *zimage = zbar_image_create(); assert(zimage); zbar_image_set_format(zimage, *(unsigned long*)"Y800"); int width = js_get_width(); int height = js_get_height(); zbar_image_set_size(zimage, width, height); size_t bloblen = width * height; unsigned char *blob = malloc(bloblen); zbar_image_set_data(zimage, blob, bloblen, zbar_image_free_data); js_read_image(blob, bloblen); zbar_process_image(processor, zimage); // print results 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); if(typ == ZBAR_PARTIAL) continue; js_output_result(zbar_get_symbol_name(typ), zbar_get_addon_name(typ), zbar_symbol_get_data(sym)); } zbar_image_destroy(zimage); if(zbar_processor_is_visible(processor)) { zbar_processor_user_wait(processor, -1); } zbar_processor_destroy(processor); return 0; }
int main (int argc, char **argv) { if(argc < 2) return(1); /* create a reader */ scanner = zbar_image_scanner_create(); /* configure the reader */ zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1); /* obtain image data */ int width = 1920, height = 1080; void *raw = NULL; get_yuv_data(argv[1], &width, &height, &raw); /* 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 */ int n = zbar_scan_image(scanner, image); if(0==n||-1==n) { printf("no symbols were found or -1 if an error occurs\n"); } /* extract results */ const zbar_symbol_t *symbol = zbar_image_first_symbol(image); for(; symbol; symbol = zbar_symbol_next(symbol)) { /* do something useful with results */ zbar_symbol_type_t typ = zbar_symbol_get_type(symbol); const char *data = zbar_symbol_get_data(symbol); printf("decoded %s symbol \"%s\"\n", zbar_get_symbol_name(typ), data); } /* clean up */ zbar_image_destroy(image); zbar_image_scanner_destroy(scanner); return(0); }
static int image_set_format (zbarImage *self, PyObject *value, void *closure) { if(!value) { PyErr_SetString(PyExc_TypeError, "cannot delete format attribute"); return(-1); } char *format; Py_ssize_t len; if(PyString_AsStringAndSize(value, &format, &len) || !format || len != 4) { PyErr_Format(PyExc_ValueError, "format '%.50s' is not a valid four character code", format); return(-1); } zbar_image_set_format(self->zimg,*((unsigned long*)format)); return(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); }
gboolean zbar_gtk_image_from_pixbuf (zbar_image_t *zimg, GdkPixbuf *pixbuf) { /* apparently should always be packed RGB? */ GdkColorspace colorspace = gdk_pixbuf_get_colorspace(pixbuf); if(colorspace != GDK_COLORSPACE_RGB) { g_warning("non-RGB color space not supported: %d\n", colorspace); return(FALSE); } int nchannels = gdk_pixbuf_get_n_channels(pixbuf); int bps = gdk_pixbuf_get_bits_per_sample(pixbuf); long type = 0; /* these are all guesses... */ if(nchannels == 3 && bps == 8) type = fourcc('R','G','B','3'); else if(nchannels == 4 && bps == 8) type = fourcc('B','G','R','4'); /* FIXME alpha flipped?! */ else if(nchannels == 1 && bps == 8) type = fourcc('Y','8','0','0'); else if(nchannels == 3 && bps == 5) type = fourcc('R','G','B','R'); else if(nchannels == 3 && bps == 4) type = fourcc('R','4','4','4'); /* FIXME maybe? */ else { g_warning("unsupported combination: nchannels=%d bps=%d\n", nchannels, bps); return(FALSE); } zbar_image_set_format(zimg, type); /* FIXME we don't deal w/bpl... * this will cause problems w/unpadded pixbufs :| */ unsigned pitch = gdk_pixbuf_get_rowstride(pixbuf); unsigned width = pitch / ((nchannels * bps) / 8); if((width * nchannels * 8 / bps) != pitch) { g_warning("unsupported: width=%d nchannels=%d bps=%d rowstride=%d\n", width, nchannels, bps, pitch); return(FALSE); } unsigned height = gdk_pixbuf_get_height(pixbuf); /* FIXME this isn't correct either */ unsigned long datalen = width * height * nchannels; zbar_image_set_size(zimg, width, height); /* when the zbar image is released, the pixbuf will be * automatically be released */ zbar_image_set_userdata(zimg, pixbuf); zbar_image_set_data(zimg, gdk_pixbuf_get_pixels(pixbuf), datalen, zbar_gtk_release_pixbuf); #ifdef DEBUG_ZBARGTK g_message("colorspace=%d nchannels=%d bps=%d type=%.4s(%08lx)\n" "\tpitch=%d width=%d height=%d datalen=0x%lx\n", colorspace, nchannels, bps, (char*)&type, type, pitch, width, height, datalen); #endif return(TRUE); }
static GstFlowReturn gst_zbar_transform_frame_ip (GstVideoFilter * vfilter, GstVideoFrame * frame) { GstZBar *zbar = GST_ZBAR (vfilter); gpointer data; gint stride, height; zbar_image_t *image; const zbar_symbol_t *symbol; int n; image = zbar_image_create (); /* all formats we support start with an 8-bit Y plane. zbar doesn't need * to know about the chroma plane(s) */ data = GST_VIDEO_FRAME_COMP_DATA (frame, 0); stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); height = GST_VIDEO_FRAME_HEIGHT (frame); zbar_image_set_format (image, GST_MAKE_FOURCC ('Y', '8', '0', '0')); zbar_image_set_size (image, stride, height); zbar_image_set_data (image, (gpointer) data, stride * height, NULL); /* scan the image for barcodes */ n = zbar_scan_image (zbar->scanner, image); if (n == 0) goto out; /* extract results */ symbol = zbar_image_first_symbol (image); for (; symbol; symbol = zbar_symbol_next (symbol)) { zbar_symbol_type_t typ = zbar_symbol_get_type (symbol); const char *data = zbar_symbol_get_data (symbol); gint quality = zbar_symbol_get_quality (symbol); GST_DEBUG_OBJECT (zbar, "decoded %s symbol \"%s\" at quality %d", zbar_get_symbol_name (typ), data, quality); if (zbar->cache && zbar_symbol_get_count (symbol) != 0) continue; if (zbar->message) { GstMessage *m; GstStructure *s; /* post a message */ s = gst_structure_new ("barcode", "timestamp", G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (frame->buffer), "type", G_TYPE_STRING, zbar_get_symbol_name (typ), "symbol", G_TYPE_STRING, data, "quality", G_TYPE_INT, quality, NULL); m = gst_message_new_element (GST_OBJECT (zbar), s); gst_element_post_message (GST_ELEMENT (zbar), m); } } out: /* clean up */ zbar_image_scanner_recycle_image (zbar->scanner, image); zbar_image_destroy (image); return GST_FLOW_OK; }
int c_zbar(IMG(x), int*m, TBarcode* result) { //printf("hello\n"); /* create a reader */ zbar_image_scanner_t * scanner = zbar_image_scanner_create(); /* configure the reader */ zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1); /* obtain image data */ int width = xsc2+1, height = xsr2+1; if (xsc1!=0 || xsr1!=0 || xsstep != width) { printf("c1=%d c2=%d r1=%d r2=%d step=%d\n",xsc1,xsc2,xsr1,xsr2,xsstep); return 1; } void *raw = xpSrc; //get_data(argv[1], &width, &height, &raw); /* 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, NULL); //printf("after set\n"); /* scan the image for barcodes */ int n = zbar_scan_image(scanner, image); //printf("scan_image code: %d\n",n); /* extract results */ int k = 0; const zbar_symbol_t *symbol = zbar_image_first_symbol(image); for(; symbol; symbol = zbar_symbol_next(symbol)) { /* do something useful with results */ zbar_symbol_type_t typ = zbar_symbol_get_type(symbol); result[k].symbol_type = zbar_get_symbol_name(typ); const char *data = zbar_symbol_get_data(symbol); result[k].symbol_value = data; // printf("decoded %s symbol \"%s\"\n",zbar_get_symbol_name(typ), data); int np = zbar_symbol_get_loc_size(symbol); //printf("np=%d\n",np); int j,x,y,r1,c1,r2,c2; c1 = c2 = zbar_symbol_get_loc_x(symbol,0); r1 = r2 = zbar_symbol_get_loc_y(symbol,0); for (j=1; j<np; j++) { x = zbar_symbol_get_loc_x(symbol,j); y = zbar_symbol_get_loc_y(symbol,j); if (y<r1) r1 = y; if (y>r2) r2 = y; if (x<c1) c1 = x; if (x>c2) c2 = x; //printf("j=%d\n",j); } result[k].bbr1 = r1; result[k].bbr2 = r2; result[k].bbc1 = c1; result[k].bbc2 = c2; k++; if(k>=50) break; } /* clean up */ zbar_image_destroy(image); *m = k; return n; }
void process_QR(IplImage* img, QR_Data * data, IplImage* outimg) { // Data extracted from the ZBar Image int width = 0; int height = 0; void *raw = NULL; // Data from the QR code and its position/angle int qr_length = 0; // The length of the code in pixels double qr_distance = 0; // How far the qr code is (altitude) double qr_angle = 0; // Angle of the code from the right x-axis double qr_angle_deg = 0;// Same as above but in degrees double dis2Mid = 0; // Distance from the camera middle to code double theta1 = 0; // the arctan of the y' and x' axes double theta2 = 0; // the angle between the two axes double theta2_deg = 0; // theta2 in radians double x_d = 0; double y_d = 0; double x_ab = 0; double y_ab = 0; int qr_x, qr_y; // The data from the QR Code char text[80]; // ZBar Scanner for C zbar_image_scanner_t* scanner = zbar_image_scanner_create(); // configure the scanner zbar_image_scanner_set_config(scanner, 0, ZBAR_CFG_ENABLE, 1); // Extract data from the image width = img->width; height = img->height; raw = (void *) img->imageData; // Wrap the 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 QR int n = zbar_scan_image(scanner, image); /* extract results */ const zbar_symbol_t *symbol = zbar_image_first_symbol(image); for(; symbol; symbol = zbar_symbol_next(symbol)) { // Cycle through each symbol found zbar_symbol_type_t typ = zbar_symbol_get_type(symbol); const char *data = zbar_symbol_get_data(symbol); printf("decoded %s symbol \"%s\"\n", zbar_get_symbol_name(typ), data); sscanf(data, "%d %d", &qr_x, &qr_y); printf("QR_X: %i\n", qr_x); printf("QR_Y: %i\n", qr_y); // Find the angle between the lines CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* ptseq = cvCreateSeq(CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvContour), sizeof(CvPoint), storage); CvPoint pts[4]; int i = 0; for (i = 0; i < 4; ++i) { CvPoint point = cvPoint(zbar_symbol_get_loc_x(symbol,i), zbar_symbol_get_loc_y(symbol,i)); cvSeqPush(ptseq, &point); pts[i] = point; } CvBox2D rect = cvMinAreaRect2(ptseq, 0); // Draw the outline rectangle for (i = 0; i < 4; ++i) { cvLine(outimg, pts[i], pts[(i+1)%4], CV_RGB(0, 0, 255), 5, 8, 0); } // Get the distance from the code to the camera qr_length = sqrt(abs(pts[0].x * pts[0].x - pts[1].x * pts[1].x) + abs(pts[0].y * pts[0].y - pts[1].y * pts[1].y)); qr_distance = qr_length * DISTANCE_M + DISTANCE_B; printf("Length: %i\n", qr_length); printf("Distance: %f\n", qr_distance); // Find the relative location // Get the angle of the circled rectangle qr_angle = -rect.angle; if (pts[0].x > pts[3].x && pts[0].y > pts[3].y) qr_angle += 90; else if (pts[0].x > pts[3].x && pts[0].y < pts[3].y) qr_angle += 180; else if (pts[0].x < pts[3].x && pts[0].y < pts[3].y) qr_angle += 270; else if (pts[0].x == pts[1].x && pts[0].y == pts[3].y) { if (pts[0].x < pts[3].x && pts[0].y < pts[1].y) qr_angle = 0; else qr_angle = 180; } else if (pts[0].x == pts[3].x && pts[0].y == pts[1].y) { if (pts[0].x < pts[1].x && pts[0].y > pts[3].y) qr_angle = 90; else qr_angle = 270; } printf("Angle: %f\n", qr_angle); //Draw a line on the angle qr_angle = qr_angle * 3.1415 / 180; CvPoint mid = cvPoint((pts[0].x + pts[2].x) / 2, (pts[0].y + pts[2].y)/2); CvPoint p2 = cvPoint(mid.x + 25*cos(qr_angle), mid.y - 25*sin(qr_angle)); cvLine(outimg,mid, p2, CV_RGB(0,255,0),5,8,0); // Get the relative location based on the data of the QR code // QR format: x y // x and y are seperated by a single space // Check if the QR is in the right format cvLine(outimg,mid, cvPoint(MID_X,MID_Y), CV_RGB(255,0,0),5,8,0); // Relative position (in pixel) dis2Mid = sqrt((mid.x - MID_X) * (mid.x - MID_X) + (mid.y - MID_Y) * (mid.y - MID_Y)); printf("Distance to Quad: %f\n", dis2Mid); theta1 = atan2(MID_Y - mid.y, MID_X - mid.x) * 180 / MATH_PI; qr_angle_deg = qr_angle * 180 / MATH_PI; theta2_deg = 90 - theta1 - qr_angle_deg; theta2 = theta2_deg * MATH_PI / 180; x_d = dis2Mid * sin(theta2); y_d = dis2Mid * cos(theta2); // Display message onto the image CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, 8); sprintf(text, "Attitude: %f", qr_distance); cvPutText(outimg, text, cvPoint(30,30), &font, cvScalar(255, 255, 255, 0)); sprintf(text, "Angle: %f", qr_angle_deg); cvPutText(outimg, text, cvPoint(30,50), &font, cvScalar(255, 255, 255, 0)); x_ab = x_d + qr_x; y_ab = y_d + qr_y; sprintf(text, "Abs. Pos: (%f, %f)", x_ab, y_ab); cvPutText(outimg, text, cvPoint(30,70), &font, cvScalar(255, 255, 255, 0)); } }
static int scan_image (IplImage * image) { if(exit_code == 3) return(-1); int found = 0; if(exit_code == 3) return(-1); zbar_image_t *zimage = zbar_image_create(); assert(zimage); zbar_image_set_format(zimage, *(unsigned long*)"Y800"); int width = image->width; int height = image->height; 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); memcpy(blob, image->imageData, image->imageSize); 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); if(typ == ZBAR_PARTIAL) continue; else if(!xmllvl) printf("%s%s:%s\n", zbar_get_symbol_name(typ), zbar_get_addon_name(typ), zbar_symbol_get_data(sym)); else if(xmllvl < 0) printf("%s\n", zbar_symbol_get_data(sym)); else { if(xmllvl < 3) { xmllvl++; //printf("<index num='%u'>\n", seq); } zbar_symbol_xml(sym, &xmlbuf, &xmlbuflen); printf("%s\n", xmlbuf); } found++; num_symbols++; } if(xmllvl > 2) { xmllvl--; printf("</index>\n"); } fflush(stdout); zbar_image_destroy(zimage); num_images++; if(zbar_processor_is_visible(processor)) { printf("waiting for q\n"); 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); }//scan_image
static GstFlowReturn gst_skor_sink_transform_frame_ip (GstVideoFilter * vfilter, GstVideoFrame * frame) { GstSkorSink *sink = GST_SKORSINK (vfilter); gpointer data; gint stride, height; zbar_image_t *image; const zbar_symbol_t *symbol; int n; image = zbar_image_create (); /* all formats we support start with an 8-bit Y plane. zbar doesn't need * to know about the chroma plane(s) */ data = GST_VIDEO_FRAME_COMP_DATA (frame, 0); stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0); height = GST_VIDEO_FRAME_HEIGHT (frame); zbar_image_set_format (image, GST_MAKE_FOURCC ('Y', '8', '0', '0')); zbar_image_set_size (image, stride, height); zbar_image_set_data (image, (gpointer) data, stride * height, NULL); /* scan the image for barcodes */ n = zbar_scan_image (sink->scanner, image); if (G_UNLIKELY (n == -1)) { GST_WARNING_OBJECT (sink, "Error trying to scan frame. Skipping"); goto out; } if (n == 0) goto out; /* extract results */ symbol = zbar_image_first_symbol (image); for (; symbol; symbol = zbar_symbol_next (symbol)) { zbar_symbol_type_t typ = zbar_symbol_get_type (symbol); const char *data = zbar_symbol_get_data (symbol); gint quality = zbar_symbol_get_quality (symbol); GST_DEBUG_OBJECT (sink, "decoded %s symbol \"%s\" at quality %d", zbar_get_symbol_name (typ), data, quality); if (sink->cache && zbar_symbol_get_count (symbol) != 0) continue; if (sink->data_consumer) sink->data_consumer (data); if (sink->message) { GstMessage *m; GstStructure *s; GstSample *sample; GstCaps *sample_caps; s = gst_structure_new ("barcode", "timestamp", G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (frame->buffer), "type", G_TYPE_STRING, zbar_get_symbol_name (typ), "symbol", G_TYPE_STRING, data, "quality", G_TYPE_INT, quality, NULL); if (sink->attach_frame) { /* create a sample from image */ sample_caps = gst_video_info_to_caps (&frame->info); sample = gst_sample_new (frame->buffer, sample_caps, NULL, NULL); gst_caps_unref (sample_caps); gst_structure_set (s, "frame", GST_TYPE_SAMPLE, sample, NULL); gst_sample_unref (sample); } m = gst_message_new_element (GST_OBJECT (sink), s); gst_element_post_message (GST_ELEMENT (sink), m); } else if (sink->attach_frame) GST_WARNING_OBJECT (sink, "attach-frame=true has no effect if message=false"); } out: /* clean up */ zbar_image_scanner_recycle_image (sink->scanner, image); zbar_image_destroy (image); return GST_FLOW_OK; }