Commits

Lazar Sumar  committed a518e60

Fixing build.

  • Participants
  • Parent commits e9d53d2

Comments (0)

Files changed (5)

File Cosc428_NPR/contour.cpp

     findContours(image, this->contours, this->hierarchy, CV_RETR_TREE, approximation);
 }
 
-Contours::Contour Contours::root() {
-    return Contour(this, 0);
+Contours::Contour Contours::getRoot() {
+    return Contour(this, this->root);
+}
+
+void Contours::remove(const Contour& c) {
+    int prev = getIndex(c.index, PREV);
+    int next = getIndex(c.index, NEXT);
+    int parent = getIndex(c.index, PARENT);
+    
+    if (parent < 0) {
+        this->root = getIndex(c.index, FIRST_CHILD);
+    } else if (prev < 0 && next < 0) {
+        this->hierarchy[parent][FIRST_CHILD] = getIndex(c.index, FIRST_CHILD);
+    } else if (prev < 0) {
+        this->hierarchy[parent][FIRST_CHILD] = getIndex(c.index, FIRST_CHILD);
+    }
+}
+
+void Contours::clear() {
+    this->contours.clear();
+    this->hierarchy.clear();
 }
 
 Contours::Contour::Contour(Contours* container, int index) {
 Contours::Contour Contours::Contour::firstChild() {
     this->index = this->container->getIndex(this->index, FIRST_CHILD);
 }
+
+vector<Point>* Contours::Contour::get() {
+    return &(this->container->contours[this->index]);
+}

File Cosc428_NPR/contour.h

 private:
     vector<vector<Point> > contours;
     vector<Vec4i> hierarchy;
+    int root;
     
     int getIndex(int myIndex, int linkType); // linkType is NEXT, PREV, PARENT or FIRST_CHILD
 public:
         Contours* container;
         int index;
         
-        Contour(Contours* container, int index);
     public:
+        Contour(Contours* container, int index = 0);
         Contour(const Contour& c);
         
         Contour next();
         Contour parent();
         Contour firstChild();
         
+        vector<Point>* get();
+        
         friend class Contours;
     };
     friend class Contours::Contour;
     
     void Find(Mat& image, int approximation = CV_CHAIN_APPROX_SIMPLE);
-    Contour root();
+    Contour getRoot();
+    
+    void remove(const Contour& c);
+    void clear();
 };
 
 

File Cosc428_NPR/contours.cpp

 
 const char* wndname = "Number Plate Detection";
 
+void findPolygons( const Mat& image, Contours& contours, double canny_threshold, double incremental_threshold_count) {
+   contours.clear();
+
+	if (incremental_threshold_count < 0 && canny_threshold > 0) {
+		incremental_threshold_count = 1;
+	}
+    
+    Mat pyr, timg, gray0(image.size(), CV_8U), gray;
+    
+    // down-scale and upscale the image to filter out the noise
+    pyrDown(image, pyr, Size(image.cols/2, image.rows/2));
+    pyrUp(pyr, timg, image.size());
+    
+    // find squares in every color plane of the image
+    for( int c = 0; c < image.channels(); c++ )
+    {
+        int ch[] = {c, 0};
+        mixChannels(&timg, 1, &gray0, 1, ch, 1);
+        
+		// try several threshold levels
+        for( int l = 0; l < incremental_threshold_count; l++ )
+        {
+            // hack: use Canny instead of zero threshold level.
+            // Canny helps to catch squares with gradient shading
+            if( l == 0 )
+            {
+				if (canny_threshold > 0) {
+					// apply Canny. Take the upper threshold from slider
+					// and set the lower to 0 (which forces edges merging)
+					Canny(gray0, gray, 0, canny_threshold, 5);
+					// dilate canny output to remove potential
+					// holes between edge segments
+					dilate(gray, gray, Mat(), Point(-1,-1));
+				} else {
+					continue;
+				}
+            }
+            else
+            {
+                // apply threshold if l!=0:
+                //     tgray(x,y) = gray(x,y) < (l+1)*255/N ? 255 : 0
+                gray = gray0 >= (l+1)*255/incremental_threshold_count;
+            }
+			
+			// find contours and store them all as a list
+            contours.Find(gray, CV_CHAIN_APPROX_SIMPLE);
+        }
+    }
+}
+
 // returns sequence of squares detected on the image.
 // the sequence is stored in the specified memory storage
 void findPolygons( const Mat& image, vector<vector<Point> >& polygons, vector<Vec4i>& hierarchy, double canny_threshold, int incremental_threshold_count )
 			
 			// find contours and store them all as a list
             findContours(gray, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
-
+            
 			polygons.insert(polygons.begin(), contours.begin(), contours.end());
         }
     }

File Cosc428_NPR/contours.h

 using namespace cv;
 using namespace std;
 
-#include "hierarchy.h"
 #include "util.h"
+#include "contour.h"
 
 #define DEF_ARC_PERCENT 0.02
 #define NO_VALUE -1
 
 #include "perspective.h"
 
-void getContours(const Mat& image, vector<vector<Point> >& polygons, vector<Vec4i>& hierarchy);
 void findPolygons( const Mat& image, vector<vector<Point> >& polygons, vector<Vec4i>& hierarchy, double canny_threshold, int incremental_threshold_count );
 void filterPolygons(vector<vector<Point> >& polygons, vector<vector<Point> >& filtered_polygons, PolygonFilter& filter);
-void filterPolygons(vector<Hierarchy>& polygons, vector<Hierarchy>& filtered_polygons, PolygonFilter& filter);
-void findPolygons( const Mat& image, vector<Hierarchy>& hierarchy, double canny_threshold, int incremental_threshold_count, PolygonFilter filter );
 void drawPolygons( Mat& image, const vector<vector<Point> >& squares );
 
 

File Cosc428_NPR/segmentation.h

 #include "perspective.h"
 #include "contours.h"
 #include "util.h"
-#include "hierarchy.h"
 
 #define DERIVATIVE_THRESHOLD 0
 #define ABSOLUTE_THRESHOLD 1
 
 void segmentByBlankColumn(Mat& image, vector<Mat>& dst, double threshold, int type = DERIVATIVE_THRESHOLD);
 
-#endif
+#endif