Skip to content

Commit e699c0d

Browse files
first init
0 parents  commit e699c0d

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CC=g++
2+
ARCH=-arch x86_64
3+
4+
5+
INCLUDE_FLAGS=-I/usr/local/include
6+
CFLAGS=-c -Wall $(INCLUDE_FLAGS)
7+
LDFLAGS= -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lzbar
8+
9+
SOURCES = main.cpp
10+
OBJECTS=$(SOURCES:.cpp=.o)
11+
12+
EXECUTABLE=main
13+
14+
all : $(SOURCES) $(EXECUTABLE)
15+
16+
$(EXECUTABLE) : $(OBJECTS) Makefile
17+
$(CC) $(ARCH) $(LDFLAGS) $(OBJECTS) -o $@
18+
19+
.cpp.o:
20+
$(CC) $(CFLAGS) $< -o $@

main

59.1 KB
Binary file not shown.

main.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include <opencv2/highgui/highgui.hpp>
2+
#include <opencv2/imgproc/imgproc.hpp>
3+
#include <zbar.h>
4+
#include <iostream>
5+
6+
using namespace cv;
7+
using namespace std;
8+
using namespace zbar;
9+
10+
//g++ main.cpp /usr/local/include/ /usr/local/lib/ -lopencv_highgui.2.4.8 -lopencv_core.2.4.8
11+
12+
int main(int argc, char* argv[])
13+
{
14+
VideoCapture cap(0); // open the video camera no. 0
15+
16+
// cap.set(CV_CAP_PROP_FRAME_WIDTH,800);
17+
// cap.set(CV_CAP_PROP_FRAME_HEIGHT,640);
18+
19+
if (!cap.isOpened()) // if not success, exit program
20+
{
21+
cout << "Cannot open the video cam" << endl;
22+
return -1;
23+
}
24+
25+
26+
ImageScanner scanner;
27+
scanner.set_config(ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
28+
29+
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
30+
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
31+
32+
cout << "Frame size : " << dWidth << " x " << dHeight << endl;
33+
34+
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
35+
36+
while (1)
37+
{
38+
Mat frame;
39+
40+
bool bSuccess = cap.read(frame); // read a new frame from video
41+
42+
if (!bSuccess) //if not success, break loop
43+
{
44+
cout << "Cannot read a frame from video stream" << endl;
45+
break;
46+
}
47+
48+
Mat grey;
49+
cvtColor(frame,grey,CV_BGR2GRAY);
50+
51+
int width = frame.cols;
52+
int height = frame.rows;
53+
uchar *raw = (uchar *)grey.data;
54+
// wrap image data
55+
Image image(width, height, "Y800", raw, width * height);
56+
// scan the image for barcodes
57+
int n = scanner.scan(image);
58+
// extract results
59+
for(Image::SymbolIterator symbol = image.symbol_begin();
60+
symbol != image.symbol_end();
61+
++symbol) {
62+
vector<Point> vp;
63+
// do something useful with results
64+
cout << "decoded " << symbol->get_type_name() << " symbol \"" << symbol->get_data() << '"' <<" "<< endl;
65+
int n = symbol->get_location_size();
66+
for(int i=0;i<n;i++){
67+
vp.push_back(Point(symbol->get_location_x(i),symbol->get_location_y(i)));
68+
}
69+
RotatedRect r = minAreaRect(vp);
70+
Point2f pts[4];
71+
r.points(pts);
72+
for(int i=0;i<4;i++){
73+
line(frame,pts[i],pts[(i+1)%4],Scalar(255,0,0),3);
74+
}
75+
//cout<<"Angle: "<<r.angle<<endl;
76+
}
77+
78+
imshow("MyVideo", frame); //show the frame in "MyVideo" window
79+
80+
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
81+
{
82+
cout << "esc key is pressed by user" << endl;
83+
break;
84+
}
85+
}
86+
return 0;
87+
88+
}

main.o

52.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)