Skip to content

Clean up code and Makefile, remove binary files #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
/main
22 changes: 5 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 $@
main: main.cpp
$(CXX) $(CFLAGS) $(LDFLAGS) $< -o $@
Binary file removed main
Binary file not shown.
134 changes: 67 additions & 67 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <zbar.h>
#include <iostream>

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<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);
}
// cout<<"Angle: "<<r.angle<<endl;
}

namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
imshow("Video", frame); // show the frame in "Video" window

while (1)
if (waitKey(30) == 27) // wait for 'esc' key press for 30ms. If 'esc' key is
// pressed, break loop
{
Mat frame;

bool bSuccess = cap.read(frame); // read a new frame from video

if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}

Mat grey;
cvtColor(frame,grey,CV_BGR2GRAY);

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);
// 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);
}
//cout<<"Angle: "<<r.angle<<endl;
}

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;
}
cout << "esc key is pressed by user" << endl;
break;
}
return 0;
}

}
return EXIT_SUCCESS;
}
Binary file removed main.o
Binary file not shown.