void qrcode_check (SDL_Surface *screen, char *payload) { struct quirc *qr; int count = 0; int i = 0; qr = quirc_new(); if (!qr) { perror("couldn't allocate QR decoder"); return; } if (quirc_resize(qr, screen->w, screen->h) < 0) { perror("couldn't allocate QR buffer"); return; } rgb32_to_luma(screen->pixels, screen->pitch, screen->w, screen->h, quirc_begin(qr, NULL, NULL), screen->w); quirc_end(qr); count = quirc_count(qr); for (i = 0; i < count; i++) { struct quirc_code code; struct quirc_data data; quirc_decode_error_t err; quirc_extract(qr, i, &code); err = quirc_decode(&code, &data); if (! err) { strcpy(payload, (char *)data.payload); } } quirc_destroy(qr); }
static int run_tests(int argc, char **argv) { struct result_info sum; int count = 0; int i; decoder = quirc_new(); if (!decoder) { perror("quirc_new"); return -1; } printf(" %-30s %17s %11s\n", "", "Time (ms)", "Count"); printf(" %-30s %5s %5s %5s %5s %5s\n", "Filename", "Load", "ID", "Total", "ID", "Dec"); puts("----------------------------------------" "---------------------------------------"); memset(&sum, 0, sizeof(sum)); for (i = 0; i < argc; i++) { struct result_info info; if (test_scan(argv[i], &info) > 0) { add_result(&sum, &info); count++; } } if (count > 1) print_result("TOTAL", &sum); quirc_destroy(decoder); return 0; }
static int run_scanner(void) { struct quirc *qr; struct camera cam; struct mjpeg_decoder mj; int ret; if (camera_init(&cam, camera_path, video_width, video_height) < 0) return -1; camera_set_gain(&cam, gain_request); qr = quirc_new(); if (!qr) { perror("couldn't allocate QR decoder"); goto fail_qr; } if (quirc_resize(qr, cam.width, cam.height) < 0) { perror("couldn't allocate QR buffer"); goto fail_qr_resize; } mjpeg_init(&mj); ret = main_loop(&cam, qr, &mj); mjpeg_free(&mj); quirc_destroy(qr); camera_free(&cam); return 0; fail_qr_resize: quirc_destroy(qr); fail_qr: camera_free(&cam); return 0; }
/** MAIN function. -------------------------------------------------------------------------------*/ int main( int argc, char** argv ) { Size boardSize, imageSize; float squareSize = 1.f, aspectRatio = 1.f; Mat cameraMatrix, distCoeffs; //DEPRECATE proposal const char* outputFilename = "out_camera_data.yml"; //DEPRECATE proposal const char* inputFilename = 0; int i, nframes = 15; bool writeExtrinsics = false, writePoints = false; bool undistortImage = false; int flags = 0; VideoCapture capture; bool flipVertical = false; bool showUndistorted = false; bool videofile = false; int delay = 1000; clock_t prevTimestamp = 0; int mode = DETECTION; int cameraId = 0; vector<vector<Point2f> > imagePoints; vector<string> imageList; if ( getOpt(argc, argv, &boardSize, &squareSize, &nframes, &aspectRatio, &delay, &flags, &writeExtrinsics, &writePoints, &flipVertical, &showUndistorted, &videofile, &cameraId, inputFilename, outputFilename) != 0) return -1; if( inputFilename ) { if( !videofile && readStringList(inputFilename, imageList) ) mode = CAPTURING; else capture.open(inputFilename); } else capture.open(cameraId); if( !capture.isOpened() && imageList.empty() ) return fprintf(stderr, "Could not initialize video (%d) capture\n", cameraId ), -2; if( !imageList.empty() ) nframes = (int)imageList.size(); if( capture.isOpened() ) printf("%s", liveCaptureHelp); namedWindow("Image View", 1); bool qrfound = false; int qr_pixel_size; struct quirc *q; q = quirc_new(); for(i = 0;;i++) { Mat view, viewGray; bool blink = false; if( capture.isOpened() ) { Mat view0; capture >> view0; view0.copyTo(view); } else if( i < (int)imageList.size() )
static int run_scanner(void) { struct quirc *qr; struct camera cam; struct mjpeg_decoder mj; const struct camera_parms *parms; camera_init(&cam); if (camera_open(&cam, camera_path, video_width, video_height, 25, 1) < 0) { perror("camera_open"); goto fail_qr; } if (camera_map(&cam, 8) < 0) { perror("camera_map"); goto fail_qr; } if (camera_on(&cam) < 0) { perror("camera_on"); goto fail_qr; } if (camera_enqueue_all(&cam) < 0) { perror("camera_enqueue_all"); goto fail_qr; } parms = camera_get_parms(&cam); qr = quirc_new(); if (!qr) { perror("couldn't allocate QR decoder"); goto fail_qr; } if (quirc_resize(qr, parms->width, parms->height) < 0) { perror("couldn't allocate QR buffer"); goto fail_qr_resize; } mjpeg_init(&mj); if (main_loop(&cam, qr, &mj) < 0) goto fail_main_loop; mjpeg_free(&mj); quirc_destroy(qr); camera_destroy(&cam); return 0; fail_main_loop: mjpeg_free(&mj); fail_qr_resize: quirc_destroy(qr); fail_qr: camera_destroy(&cam); return -1; }