Ejemplo n.º 1
0
/**
 * This is a (modified) test program written by Michael Young
 * (https://github.com/ayoungprogrammer/WebcamCodeScanner). It was modified to
 * work with the Raspicam.
 */
int main(int argc, char* argv[])
{
	PiCamera cam; // open the video camera no. 0
	ImageScanner scanner;  
	scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);  

	namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

	while (1)
	{
		Mat frame = cam.Snap();
		Mat grey;
		cvtColor(frame,grey,CV_BGR2GRAY);

		int width = frame.cols;  
		int height = frame.rows;  
		uchar *raw = (uchar *)grey.data;  
		// wrap image data  
		zbar::Image image(width, height, "Y800", raw, width * height);  
		// scan the image for barcodes  
		int n = scanner.scan(image);  
		// extract results  
		for(Image::SymbolIterator symbol = image.symbol_begin();  
				symbol != image.symbol_end();  
				++symbol) {  
			vector<Point> vp;  
			// do something useful with results  
			cout << "decoded " << symbol->get_type_name()  << " symbol \"" << symbol->get_data() << '"' <<" "<< endl;  
			int n = symbol->get_location_size();  
			for(int i=0;i<n;i++){  
				vp.push_back(Point(symbol->get_location_x(i),symbol->get_location_y(i))); 
			}  
			RotatedRect r = minAreaRect(vp);  
			Point2f pts[4];  
			r.points(pts);  
			for(int i=0;i<4;i++){  
				line(frame,pts[i],pts[(i+1)%4],Scalar(255,0,0),3);  
			}  
		}  

		imshow("MyVideo", frame); //show the frame in "MyVideo" window

		if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
		{
			cout << "esc key is pressed by user" << endl;
			break; 
		}
	}
	return 0;

}
Ejemplo n.º 2
0
string QRScanner::getQRCode()
{
    stringstream out;

    // extract results
    for(Image::SymbolIterator symbol = myImage->symbol_begin();
    		symbol != myImage->symbol_end();
    		++symbol) {
    	out << symbol->get_type_name() << symbol->get_data();
    	// do something useful with results
    	//cout << "decoded " << symbol->get_type_name()
        //     << " symbol \"" << symbol->get_data() << '"' << endl;
    }

    return  out.str();
}
Ejemplo n.º 3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ImageScanner scanner;
    //scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
    scanner.set_config(ZBAR_QRCODE, ZBAR_CFG_ENABLE, 1);

    QImage qimage;
    bool imgLoaded = qimage.load("C:/Users/emi/Dropbox/projekts/qt/zBar_32bit/codePictures/qrCode3.png");

    if(imgLoaded == false)
    {
        qDebug() << "error loading image";
    }

    QImage convertedImage = qimage.convertToFormat(QImage::Format_Grayscale8,Qt::MonoOnly);

    int width = convertedImage.width();
    int height= convertedImage.height();


    unsigned char * data = convertedImage.bits();

    Image image(width, height, "Y800" , data, width*height);
  // Image image(width, height, "GRAY" , data, width*height);

    // scan the image for barcodes
    int n = scanner.scan(image);


    // extract results
    for(Image::SymbolIterator symbol = image.symbol_begin();
        symbol != image.symbol_end();
        ++symbol)
    {
        // do something useful with results
       qDebug() << "decoded " << QString::fromStdString(symbol->get_type_name())
             << " symbol \"" << QString::fromStdString(symbol->get_data()) << '"' << endl;
    }

    // clean up
    image.set_data(NULL, 0);

}
Ejemplo n.º 4
0
int main (int argc, char **argv)
{
    unsigned long nowTime = getCurrentTime();
    // std::cout<<"nowTime: "<<getCurrentTime()<<"\n";
    if(argc < 2) return(1);

    // create a reader
    ImageScanner scanner;

    // // configure the reader
    scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
    /* obtain image data */
    int width = 1920, height = 1080;
    char *raw = (char*)malloc(width*height);
    get_yuv_data(argv[1], width, height, raw);
    // wrap image data
    Image image(width, height, "Y800", raw, width * height);

    // scan the image for barcodes
    int n = scanner.scan(image);
    if(0==n||-1==n)
    {
      printf("no symbols were found or -1 if an error occurs");
      return -1;
    }
    // extract results
    for(Image::SymbolIterator symbol = image.symbol_begin();
        symbol != image.symbol_end();
        ++symbol)
    {
        // do something useful with results
        cout << "decoded " << symbol->get_type_name()
             << " symbol \"" << symbol->get_data() << '"' << endl;
    }

    // clean up
    image.set_data(NULL, 0);
    free(raw);
    std::cout<<getCurrentTime()-nowTime<<"\n";
    return(0);
}
Ejemplo n.º 5
0
int main(int argc, char **argv) {
    int cam_idx = 0;

    if (argc == 2) {
        cam_idx = atoi(argv[1]);
    }

    VideoCapture cap(cam_idx);
    if (!cap.isOpened()) {
        cerr << "Could not open camera." << endl;
        exit(EXIT_FAILURE);
    }
    //cap.set(CV_CAP_PROP_FRAME_WIDTH, 640);
    //cap.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

    namedWindow("captured", CV_WINDOW_AUTOSIZE);
    
    // Create a zbar reader
    ImageScanner scanner;
    
    // Configure the reader
    scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);

    for (;;) {
        // Capture an OpenCV frame
        cv::Mat frame, frame_grayscale;
        cap >> frame;

        // Convert to grayscale
        cvtColor(frame, frame_grayscale, CV_BGR2GRAY);

        // Obtain image data
        int width = frame_grayscale.cols;
        int height = frame_grayscale.rows;
        uchar *raw = (uchar *)(frame_grayscale.data);

        // Wrap image data
        Image image(width, height, "Y800", raw, width * height);

        // Scan the image for barcodes
        //int n = scanner.scan(image);
        scanner.scan(image);

        // Extract results
        int counter = 0;
        for (Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) {
            time_t now;
            tm *current;
            now = time(0);
            current = localtime(&now);

            // do something useful with results
            cout    << "[" << current->tm_hour << ":" << current->tm_min << ":" << setw(2) << setfill('0') << current->tm_sec << "] " << counter << " "
                    << "decoded " << symbol->get_type_name()
                    << " symbol \"" << symbol->get_data() << '"' << endl;

            //cout << "Location: (" << symbol->get_location_x(0) << "," << symbol->get_location_y(0) << ")" << endl;
            //cout << "Size: " << symbol->get_location_size() << endl;
            
            // Draw location of the symbols found
            if (symbol->get_location_size() == 4) {
                //rectangle(frame, Rect(symbol->get_location_x(i), symbol->get_location_y(i), 10, 10), Scalar(0, 255, 0));
                line(frame, Point(symbol->get_location_x(0), symbol->get_location_y(0)), Point(symbol->get_location_x(1), symbol->get_location_y(1)), Scalar(0, 255, 0), 2, 8, 0);
                line(frame, Point(symbol->get_location_x(1), symbol->get_location_y(1)), Point(symbol->get_location_x(2), symbol->get_location_y(2)), Scalar(0, 255, 0), 2, 8, 0);
                line(frame, Point(symbol->get_location_x(2), symbol->get_location_y(2)), Point(symbol->get_location_x(3), symbol->get_location_y(3)), Scalar(0, 255, 0), 2, 8, 0);
                line(frame, Point(symbol->get_location_x(3), symbol->get_location_y(3)), Point(symbol->get_location_x(0), symbol->get_location_y(0)), Scalar(0, 255, 0), 2, 8, 0);
            }
            
            // Get points
            /*for (Symbol::PointIterator point = symbol.point_begin(); point != symbol.point_end(); ++point) {
                cout << point << endl;
            } */
            counter++;
        }

        // Show captured frame, now with overlays!
        imshow("captured", frame);
                                                                                                                                                          
        // clean up
        image.set_data(NULL, 0);
        
        waitKey(30);
    }

    return 0;
}
Ejemplo n.º 6
0
JNIEXPORT void JNICALL Java_com_example_qr_MainActivity_nativeDetect(
		JNIEnv * jenv, jclass, jlong imageGray) {
	LOGD(
			"Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect enter");
	try {
		vector<Rect> RectFaces;
		//       ((DetectionBasedTracker*)thiz)->process(*((Mat*)imageGray));
		//       ((DetectionBasedTracker*)thiz)->getObjects(RectFaces);
		//       vector_Rect_to_Mat(RectFaces, *((Mat*)faces));

		Mat img = *((Mat*) imageGray);
		Mat imgout;
		cvtColor(img, imgout, CV_GRAY2RGB);
		int width = img.cols;
		int height = img.rows;
		uchar *raw = (uchar *) img.data;
//		uchar *raw = (uchar *) imageGray;
		// wrap image data
		Image image(width, height, "Y800", raw, width * height);
		// scan the image for barcodes
		ImageScanner scanner;
		scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);

		int n = scanner.scan(image);
		// extract results
		for (Image::SymbolIterator symbol = image.symbol_begin();
				symbol != image.symbol_end(); ++symbol) {
			vector<Point> vp;
			// do something useful with results
			cout << "decoded " << symbol->get_type_name() << " symbol \""
					<< symbol->get_data() << '"' << " " << endl;
			int n = symbol->get_location_size();
			for (int i = 0; i < n; i++) {
				vp.push_back(
						Point(symbol->get_location_x(i),
								symbol->get_location_y(i)));

			}
			RotatedRect r = minAreaRect(vp);
			Point2f pts[4];
			r.points(pts);
			for (int i = 0; i < 4; i++) {
				line(imgout, pts[i], pts[(i + 1) % 4], Scalar(255, 0, 0), 3);
			}
			cout << "Angle: " << r.angle << endl;
		}
		imshow("imgout.jpg", imgout);
		// clean up
		image.set_data(NULL, 0);
		waitKey();

	} catch (cv::Exception& e) {
		LOGD("nativeCreateObject caught cv::Exception: %s", e.what());
		jclass je = jenv->FindClass("org/opencv/core/CvException");
		if (!je)
			je = jenv->FindClass("java/lang/Exception");
		jenv->ThrowNew(je, e.what());
	} catch (...) {
		LOGD("nativeDetect caught unknown exception");
		jclass je = jenv->FindClass("java/lang/Exception");
		jenv->ThrowNew(je,
				"Unknown exception in JNI code DetectionBasedTracker.nativeDetect()");
	}
	LOGD(
			"Java_org_opencv_samples_facedetect_DetectionBasedTracker_nativeDetect exit");
}