Commits

Anonymous committed 567da29

Adding portable directory code. Perspective code still does not compile.

Comments (0)

Files changed (6)

Cosc428_NPR/image.cpp

 }
 
 Image::Image(string filename) {
-	init(imread(filename));
+    Mat tempImage = imread(filename);
+	init(tempImage);
 }
 
 

Cosc428_NPR/perspective.cpp

 
 Size plate_dims(PLATE_WIDTH, PLATE_HEIGHT); // in mm
 Size letter_dims(LETTER_WIDTH, LETTER_HEIGHT);
-
+double ratio_tolerance = 0.1;
+double angle_tolerance = 0.3;
+	
 bool checkLetterRatio(vector<Point> letter_candidate, double deviation, double ratio, bool strict) {
 	vector<bool> match_map(letter_candidate.size());
 	return checkLetterRatio(letter_candidate, match_map, deviation, ratio, strict);
 		temp = hierarchy;
 		output = &temp;
 	}
-
+    
 	sortPlateCandidates(hierarchy, prioritised_index, limit, ratio_tolerance, angle_tolerance);
 	
 	for (int k = 0; k < prioritised_index.size(); k++) {
 	} else {
 		output = &prioritised_candidates;
 	}
-
-	sortPlateCandidates(candidates, prioritised_index, limit, ratio_tolerance, angle_tolerance);
+    
+    sortPlateCandidates(candidates, prioritised_index, limit, ratio_tolerance, angle_tolerance);
 	
 	output->clear();
 	for (int i = 0; i < prioritised_index.size() && (limit < 1 || i < limit); i++) {

Cosc428_NPR/segmentation.cpp

 		Mat letter;
 		vector<Point2f> coord_map(4);
 
-		coord_map[0] = Point2f(letter_bounds[i].tl());
+		coord_map[0] = Point2f(letter_bounds[i].tl().x, letter_bounds[i].tl().y);
 		coord_map[1] = Point2f(letter_bounds[i].br().x, letter_bounds[i].tl().y);
-		coord_map[2] = Point2f(letter_bounds[i].br());
+		coord_map[2] = Point2f(letter_bounds[i].br().x, letter_bounds[i].br().y);
 		coord_map[3] = Point2f(letter_bounds[i].tl().x, letter_bounds[i].br().y);
 
 		perspectiveAdjustment(plate, letter, coord_map, LETTER_WIDTH, LETTER_HEIGHT, 0, true);

Cosc428_NPR/util.cpp

 	string filename(makeFilename(subname));
 
 	cout << "Writing image \"" << settings.temp_folder_name << "\\" << filename << "\"... ";
-	_chdir(settings.temp_folder_path.c_str());
+	CHDIR(settings.temp_folder_path.c_str());
 	imwrite(filename, img);
-	_chdir(settings.cwd.c_str());
+	CHDIR(settings.cwd.c_str());
 	cout << "written." << endl;
 
 	return filename;
 
 bool parseArgs(int argc, char **argv, Mat& src) {
 	bool success = true;
-	char* tmp = _getcwd(NULL, 256);
+	char* tmp = GETCWD(NULL, 256);
 	settings.cwd = tmp;
 	free(tmp);
 
 		i = settings.filename.length() - 1;
 		settings.filepath = settings.cwd;
 		for (; i >= 0; i--) {
-			if (settings.filename[i] == '\\' || settings.filename[i] == '/') {
-				settings.filepath = settings.cwd + "\\" + settings.filename.substr(0, i);
+			if (settings.filename[i] == '/' || settings.filename[i] == '/') {
+				settings.filepath = settings.cwd + "/" + settings.filename.substr(0, i);
 				settings.filename = settings.filename.substr(i + 1);
 				break;
 			}
 		string fn = "";
 		if (settings.filepath.length() > 0) {
 			cout << "Image located in \"" << settings.filepath << "\" folder" << endl;
-			fn += settings.filepath + "\\";
+			fn += settings.filepath + "/";
 		}
 		fn += settings.filename + settings.extension;
 		src=imread(fn, -1);
 			}
 
 			settings.temp_folder_name = settings.filename + "_temp";
-			settings.temp_folder_path = settings.filepath + "\\" + settings.temp_folder_name;
+			settings.temp_folder_path = settings.filepath + "/" + settings.temp_folder_name;
 
-			_mkdir(settings.temp_folder_path.c_str());
+			MKDIR(settings.temp_folder_path.c_str());
 
 			cout << "Created temporary folder \"" << settings.temp_folder_name << "\" to store intermediate images" << endl;
 		}

Cosc428_NPR/util.h

 
 using namespace cv;
 
+#ifdef __WIN32
+#include <direct.h>
+using namespace std;
+
+#define CHDIR _chdir
+#define GETCWD _getcwd
+#define MKDIR(dir) _mkdir(dir)
+#else
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#define CHDIR chdir
+#define GETCWD getcwd
+#define MKDIR(dir) mkdir(dir, 0777)
+#endif
+
 #define DEF_TOLERANCE 0.0
 
 class Approx {
 BINDIR=bin/
 OBJDIR=obj/
 
-$(BINDIR)$(PROG): $(OBJDIR)start.o $(OBJDIR)contours.o $(OBJDIR)hierarchy.o $(OBJDIR)image.o $(OBJDIR)perspective.o $(OBJDIR)segmentation.o $(OBJDIR)util.o
-	$(CC) $(CFLAGS) $(CINCLUDES) $(CLIBS) $(OBJDIR)start.o $(OBJDIR)contours.o $(OBJDIR)hierarchy.o $(OBJDIR)image.o $(OBJDIR)perspective.o $(OBJDIR)segmentation.o $(OBJDIR)util.o -o $(BINDIR)$(PROG)
+$(BINDIR)$(PROG): $(SRCDIR)start.cpp $(OBJDIR)contours.o $(OBJDIR)hierarchy.o $(OBJDIR)image.o $(OBJDIR)segmentation.o $(OBJDIR)util.o $(OBJDIR)perspective.o
+	$(CC) $(CFLAGS) $(CINCLUDES) $(CLIBS) $(SRCDIR)start.cpp $(OBJDIR)contours.o $(OBJDIR)hierarchy.o $(OBJDIR)image.o $(OBJDIR)perspective.o $(OBJDIR)segmentation.o $(OBJDIR)util.o -o $(BINDIR)$(PROG)
 
 $(OBJDIR)start.o: $(SRCDIR)start.cpp
 	$(CC) $(CINCLUDES) $(OBJFLAG) $(SRCDIR)start.cpp -o $(OBJDIR)start.o
 $(OBJDIR)image.o: $(SRCDIR)image.cpp $(SRCDIR)image.h
 	$(CC) $(CINCLUDES) $(OBJFLAG) $(SRCDIR)image.cpp -o $(OBJDIR)image.o
 
-$(OBJDIR)perspective.o: $(SRCDIR)perspective.cpp $(SRCDIR)perspective.h
-	$(CC) $(CINCLUDES) $(OBJFLAG) $(SRCDIR)perspective.cpp -o $(OBJDIR)perspective.o
-
 $(OBJDIR)segmentation.o: $(SRCDIR)segmentation.cpp $(SRCDIR)segmentation.h
 	$(CC) $(CINCLUDES) $(OBJFLAG) $(SRCDIR)segmentation.cpp -o $(OBJDIR)segmentation.o
 
 $(OBJDIR)util.o: $(SRCDIR)util.cpp $(SRCDIR)util.h
 	$(CC) $(CINCLUDES) $(OBJFLAG) $(SRCDIR)util.cpp -o $(OBJDIR)util.o
+
+$(OBJDIR)perspective.o: $(SRCDIR)perspective.cpp $(SRCDIR)perspective.h
+	$(CC) $(CINCLUDES) $(OBJFLAG) $(SRCDIR)perspective.cpp -o $(OBJDIR)perspective.o
+