-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also, added an unwrapped Hough lines example in prep for wrapping it.
- Loading branch information
1 parent
632494a
commit 6a70901
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6a70901
There was a problem hiding this comment.
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.
6a70901
There was a problem hiding this comment.
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?
6a70901
There was a problem hiding this comment.
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!