Skip to content

Commit

Permalink
The official 0.4 release!
Browse files Browse the repository at this point in the history
Also, added an unwrapped Hough lines example in prep for wrapping it.
  • Loading branch information
atduskgreg committed Jul 10, 2013
1 parent 632494a commit 6a70901
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
63 changes: 63 additions & 0 deletions examples/HoughLineDetection/HoughLineDetection.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import gab.opencv.*;
import org.opencv.imgproc.Imgproc;
import org.opencv.core.Mat;
import java.awt.geom.Line2D;

OpenCV opencv;

ArrayList<Line2D> lines;

void setup() {
PImage src = loadImage("film_scan.jpg");
src.resize(0, 800);
size(src.width, src.height, P2D);

opencv = new OpenCV(this, src);
opencv.findSobelEdges(1, 0);
opencv.threshold(20);

lines = findLines(opencv.getGray(), 200, 120, 5);

for(Line2D l : lines){
println(Math.toDegrees(angleOf(l)));
}

noLoop();
}

double angleOf(Line2D l){
Line2D vertical = new Line2D.Double(0,0, 0,1);

return angleBetween(l, vertical);
}

double angleBetween(Line2D line1, Line2D line2) {
double angle1 = Math.atan2(line1.getY1() - line1.getY2(),
line1.getX1() - line1.getX2());
double angle2 = Math.atan2(line2.getY1() - line2.getY2(),
line2.getX1() - line2.getX2());
return angle1-angle2;
}

ArrayList<Line2D> findLines(Mat m, int threshold, double minLength, double maxGap) {
ArrayList<Line2D> result = new ArrayList<Line2D>();

Mat lineMat = new Mat();
Imgproc.HoughLinesP(m, lineMat, 1, PI/180.0, threshold, minLength, maxGap);
for (int i = 0; i < lineMat.width(); i++) {
double[] coords = lineMat.get(0, i);
result.add(new Line2D.Double(coords[0], coords[1], coords[2], coords[3]));
}

return result;
}

void draw() {
image(opencv.getOutput(), 0, 0);
stroke(0, 255, 0);
strokeWeight(2);
for (Line2D line : lines) {
line((float)line.getX1(), (float)line.getY1(), (float)line.getX2(), (float)line.getY2());
}
}

Binary file added examples/HoughLineDetection/film_scan.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ library.version=5

# The version as the user will see it.

library.prettyVersion=0.4-beta1
library.prettyVersion=0.4


library.copyright=(c) 2013
Expand Down

3 comments on commit 6a70901

@SidSt
Copy link

@SidSt SidSt commented on 6a70901 Jul 20, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

The library 0.4 is compatible with which version of the Processing?

I tried to use version 1.5.1 of Processing and not worked.

Thank you.

@atduskgreg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been chiefly tested on Processing 2.0, both the betas and release version on multiple platforms. What error are you seeing in 1.5.1 and using which example or code?

@atduskgreg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you're reporting a bug, please post it in the issues rather than here on a commit. Thanks!

Please sign in to comment.