diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 15a8656..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24853ce --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +/main diff --git a/Makefile b/Makefile index 03b55f6..ee3048e 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,8 @@ -CC=g++ -ARCH=-arch x86_64 - - INCLUDE_FLAGS=-I/usr/local/include -CFLAGS=-c -Wall $(INCLUDE_FLAGS) -LDFLAGS= -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lzbar - -SOURCES = main.cpp -OBJECTS=$(SOURCES:.cpp=.o) - -EXECUTABLE=main - -all : $(SOURCES) $(EXECUTABLE) +CFLAGS=-Wall $(INCLUDE_FLAGS) +LDFLAGS= -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_videoio -lzbar -$(EXECUTABLE) : $(OBJECTS) Makefile - $(CC) $(ARCH) $(LDFLAGS) $(OBJECTS) -o $@ +all: main -.cpp.o: - $(CC) $(CFLAGS) $< -o $@ \ No newline at end of file +main: main.cpp + $(CXX) $(CFLAGS) $(LDFLAGS) $< -o $@ diff --git a/main b/main deleted file mode 100755 index 8d33999..0000000 Binary files a/main and /dev/null differ diff --git a/main.cpp b/main.cpp index 6c9ce15..385b39b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,88 +1,88 @@ +#include #include #include #include -#include using namespace cv; using namespace std; using namespace zbar; -//g++ main.cpp /usr/local/include/ /usr/local/lib/ -lopencv_highgui.2.4.8 -lopencv_core.2.4.8 - -int main(int argc, char* argv[]) +int main (int argc, char *argv[]) { - VideoCapture cap(0); // open the video camera no. 0 + VideoCapture cap(0); // open video capture device #0 + + // cap.set(CV_CAP_PROP_FRAME_WIDTH,800); + // cap.set(CV_CAP_PROP_FRAME_HEIGHT,640); + + if (!cap.isOpened()) // if not success, exit program + { + cout << "Unable to open video capture device." << endl; + return EXIT_FAILURE; + } + + ImageScanner scanner; + scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); - // cap.set(CV_CAP_PROP_FRAME_WIDTH,800); - // cap.set(CV_CAP_PROP_FRAME_HEIGHT,640); + double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); // get video frame width + double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); // get video frame height - if (!cap.isOpened()) // if not success, exit program + cout << "Frame size: " << dWidth << " x " << dHeight << endl; + + namedWindow("Video", CV_WINDOW_AUTOSIZE); // create window + + while (1) + { + Mat frame; + + if (!cap.read(frame)) // read frame from video or break loop { - cout << "Cannot open the video cam" << endl; - return -1; + cout << "Unable to read frame from video stream." << endl; + break; } + Mat grey; + cvtColor(frame, grey, CV_BGR2GRAY); - ImageScanner scanner; - scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1); + int width = frame.cols; + int height = frame.rows; + uchar *raw = (uchar *) grey.data; + // wrap image data + Image image(width, height, "Y800", raw, width * height); + // scan the image for barcodes + int n = scanner.scan(image); - double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video - double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video - - cout << "Frame size : " << dWidth << " x " << dHeight << endl; + // extract results + for (Image::SymbolIterator symbol = image.symbol_begin(); + symbol != image.symbol_end(); ++symbol) + { + vector 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); + } + // cout<<"Angle: "< 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;iget_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); - } - //cout<<"Angle: "<