atduskgreg / opencv-processing Goto Github PK
View Code? Open in Web Editor NEWOpenCV for Processing. A creative coding computer vision library based on the official OpenCV Java API
License: Other
OpenCV for Processing. A creative coding computer vision library based on the official OpenCV Java API
License: Other
I'm trying to do blob tracking based on both Saturation and Hue. Your OpenCV.inRange() function works great for doing either one but overwrites the input Mat object. It'd be great if that were as versatile as the inRange() function in the core library that allows multiple range arrays and/or outputs to a different object. That way you could add multiple filters to the same image more easily, for example filter for blue AND red hue, or hue and saturation etc. Unless there's a way to that already that I've missed, without having to save intermediate PImages.
Hi Greg, thanks for this library. Just wondering if there is a chance it will work on OSX 10.6 at any point? Tried as I may, I couldn't get it to show up in Contributed Libraries.
Sorry, my processing was reset to 32 bit so the problem was related to this.
Please delete.
There's a lot of functionality (like Photo.inpaint, for example) that requires a 3-channel image.
Import should be:
import gab.opencv-processing.*;
Classname should be OpenCV
I guess we should grep the error message for:
OpenCV Error: Assertion failed (blockSize % 2 == 1 && blockSize > 1) in adaptiveThreshold, file /Users/matthewepler/opencv-2.4.5/modules/imgproc/src/thresh.cpp, line 797
toPImage(), imitate(), and there are some others.
Is there a possible way to do this internally a la? http://ubaa.net/shared/processing/opencv/opencv_roi.html
This is supported in the API by initializing a new Mat as an ROI into an existing Mat like so:
Mat original = opencv.getBufferGray();
Mat roi = new Mat(original, new Rect(200,200,400,400));
Imgproc.threshold(roi, roi, 100, 255, Imgproc.THRESH_BINARY);
However, not quite sure how to support this internally. Maybe initialize a new OpenCVPro object like this:
OpenCVPro roi = new OpenCVPro(this, opencv, 50,50,100,100);
where "opencv" is an existing OpenCVPro object and the last four arguments are the x, y, width, and height of the ROI.
Something like:
void drawContours(ArrayList<MatOfPoint> cntrs) {
for (MatOfPoint contour : cntrs) {
beginShape();
Point[] points = contour.toArray();
for (int i = 0; i < points.length; i++) {
vertex((float)points[i].x, (float)points[i].y);
}
endShape();
}
}
Hi Greg
It seems like you've done a ton of work setting up the correct system libs for the specific platforms. I find myself wanting to use Mat
and other classes in my Processing code, and I need to do this to make it all work:
import gab.opencv.*;
OpenCV opencv;
opencv = new OpenCV(this, "test.jpg");
After that, I can use the core OpenCV classes. It might be awesome to make those internal setup function public, so someone could do something like this:
import gab.opencv.*;
OpenCV.init();
And it just worked. Anyway, just a few thoughts.
I’ve found a bottleneck with loadImage() that reduces frameRate in Processing when you have to process an image in realtime en every draw() routine.
That happens here, when you convert the PImage to CV format. Is there any way to make this conversion more efficient?
/**
ByteBuffer bb = ByteBuffer.allocate(matPixels.length * 4);
IntBuffer ib = bb.asIntBuffer();
ib.put(matPixels); //<---this is very slow
byte[] bvals = bb.array();
m.put(0,0, bvals);
}
Would be great if someone can improve this function (I dont now how).
Thank you!,
Juan Pablo
Alter the FindEdges example to use the color mat to see the problem. Maybe we need to raise our own error on the operations that don't support color mats? Is there a good OpenCV error type to rescue so we can re-raise?
Hyup.
if you have path to libraries like this for example
C:\Users\Mačřščýřžýěšč\Documents\Processing\libraries..........cascades
Processing cannot load cascade. Moving whole Processing folder from Documents folder somewhere else (with non-ASCII named folder) and changing path in Preferences fixes the problem.
Trying to run the examples either gives me a vague message like:
"A library relies on native code that's not available."
Or, it gives a more specific message like:
java.lang.UnsatisfiedLinkError:/~/sketchbook/libraries/opencv_processing/library/linux64/libopencv_java245.so:libopencv_nonfree.so.2.4: cannot open shared object file: No such file or directory
The examples run fine for me after adding
"export LD_LIBRARY_PATH=~/sketchbook/libraries/opencv_processing/library/linux64
$LD_LIBRARY_PATH"
to the bash profile (~/.bash_profile)
It looked like this linking issue should have been fixed in a recent release. Is the version downloaded from the Processing PDE outdated?
My OS is Fedora 19.
Probably something to do with forward slashes vs backslashes. Bah.
What architecture do you currently support?
I swear it used to circa:
https://github.com/atduskgreg/OpenCVPro/blob/45dd8eb28f7764998abcf4378fc5626ee7832b71/src/gab/opencvpro/OpenCVPro.java
https://github.com/atduskgreg/OpenCVPro/blob/45dd8eb28f7764998abcf4378fc5626ee7832b71/examples/FindEdges/FindEdges.pde
Evidence:
http://www.flickr.com/photos/unavoidablegrain/8635989723/in/set-72157633151084178
Same problem seems to be present in sobel filtering. Mat just ends up blank.
Same situation as the closed issue #26 but in windows.
Processing 2.0.1 32 bit
openCV library 0.4
Windows 8
The example works fine in 2.0b9 so I imagine this will also be fixed with the next Processing release?
I've been trying to run the opencv for processing library (0.4.4). There have been a couple issues to note.
first the library folder format is incorrect.
Currently: opencv-processing-latest>lib>opencv-245.jar
Should be: opencv_processing>library>opencv_processing.jar
opencv_processing.jar is missing all together in 0.4.4 but not in 0.4.3
After correcting these and changing opencv-245.jar to opencv_processing.jar to get the library to show up in the sketch>import library menus in Processing 2.1, I get an error "the package 'gab' does not exist". This just leads me to believe that I can't change opencv-245.jar to opencv_processing.jar.
Adding in the opencv_processing.jar from 0.4.3 allowed the examples to run. But given that it is form an older rev I would think that this is not a sufficient solution.
lastly 0.4.4 is missing library.properties which my understand is that its just a nice to have.
Implement a Blob base class that both face detection and contour tracking results can use / inherit from. This class should handle blob persistence following something like the strategy articulated here:
http://www.shiffman.net/2011/04/26/opencv-matching-faces-over-time/
or here:
https://github.com/kylemcdonald/ofxCv/blob/master/libs/ofxCv/src/Tracker.cpp
java.io.FileNotFoundException: https://github.com/atduskgreg/opencv-processing/releases/download/latest/opencv_processing.zip
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at processing.app.contrib.ContributionManager.download(ContributionManager.java:69)
at processing.app.contrib.ContributionManager$1.run(ContributionManager.java:123)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: https://github.com/atduskgreg/opencv-processing/releases/download/latest/opencv_processing.zip
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
at java.net.URLConnection.getHeaderFieldLong(Unknown Source)
at java.net.URLConnection.getContentLengthLong(Unknown Source)
at java.net.URLConnection.getContentLength(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getContentLength(Unknown Source)
at processing.app.contrib.ContributionManager.download(ContributionManager.java:65)
... 2 more
When working with video as source (using the Capture class) I get this info text twice.
OpenCV for Processing 0.4.2 by Greg Borenstein http://gregborenstein.com
Using Java OpenCV 2.4.5.0
OpenCV for Processing 0.4.2 by Greg Borenstein http://gregborenstein.com
Using Java OpenCV 2.4.5.0
If I load an image as source it's printed normally. It doesn't affect the sketch, but maybe there is some redundancy in the initialization process.
Is there a way to only get the region of interest as image output?
The method opencv.getOutput() outputs the entire image with the region of interest on it. But would it be possible to get it independently?
Currently an incomprehensible error is generated when in 32-bit mode. Instead we should generate a sensible error recommending the user set the setting in Preferences. We can detect 32-bit mode thusly:
System.getProperty("sun.arch.data.model")
Sometimes, the main Mat will change size.
For example, the in-progress WarpPerspective example, changes the shape and size of the Mat being warped. In order to do that in-place (i.e. without creating a new image as that example currently does) we need the ability to alter the width and height of the current OpenCV object and all the working Mats.
The same would hold for providing support for submat()
And, more generally, improve system for updating to a new OpenCV build so it doesn't seem so difficult.
As part of the big rename
Something along the lines of:
Mat grayMat = opencv.getBufferGray();
Mat roiMat = grayMat.submat(roi.y, roi.y+roi.height, roi.x, roi.x+roi.width );
opencv.setBufferGray(roiMat);
Should it replace the working buffer?
Imgproc.dilate(sprocketProcessor.getBufferGray(), sprocketProcessor.getBufferGray(), new Mat());
Imgproc.erode(edgeProcessor.getBufferGray(), edgeProcessor.getBufferGray(), new Mat());
Maybe including example of using them together for hole closing.
I love this library. I would have paid for it if I had had to. I am currently having a conflict in which one of my important libraries is 64bit only, and this one is 32bit only. Is there a chance this could one day be changed? Thanks! I still love it
So the user doesn't have to do these kinds of checks:
if (mouseX > 0 &&
mouseX < width-roiWidth &&
mouseY > 0 &&
mouseY < height-roiHeight) {
opencv.setROI(mouseX, mouseY, roiWidth, roiHeight);
}
But what should the result be? bufferROI simply not set? Should setROI() also return false?
I found that when working with an external camera I found wraping the opencv code in if video.available() {} statement worked best
After following these instructions to install OpenCV, I keep receiving the following error any time I try to run any of the examples:
Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(III)J at org.opencv.core.Mat.n_Mat(Native Method) at org.opencv.core.Mat.<init>(Mat.java:471) at gab.opencv.OpenCV.init(Unknown Source) at gab.opencv.OpenCV.loadFromPImage(Unknown Source) at gab.opencv.OpenCV.<init>(Unknown Source) at HueRangeSelection.setup(HueRangeSelection.java:33) at processing.core.PApplet.handleDraw(PApplet.java:1608) at processing.core.PApplet.run(PApplet.java:1530) at java.lang.Thread.run(Thread.java:695)
I've googled around and no one seems to have had similar problems.
In the getBufferGray(), getBufferColor(), etc. methods. Maybe this should be Channel?
The point is that these return a Mat rather than an image. Maybe just use Mat as in the name?
Kalman filters come in very hand for smoothing out noisy signals, like that coming from the haar cascade detection algorithms. I need it for a processing project I'm working on, so I'm going to expose that API to processing. I'll submit a pull request when I'm done.
Right now, they're findCannyEdges(), findScharrX(), findScharrY(), and findSobelEdges(). Would be good to get them down to two words each two (maybe scharr takes the direction as an argument?)
I tried to run the BackgroundSubstraction example but I just see the video.
Here's an illustration of the problem:
for (Contour contour : opencv.findContours()) {
println("this never prints");
contour.draw();
}
void setup() {
PImage src = loadImage("film_scan.jpg");
src.resize(0, 800);
size(src.width, src.height, P2D);
opencv = new OpenCV(this, src);
// opencv.findCannyEdges(20, 75);
opencv.findSobelEdges(0, 1);
opencv.threshold(50);
lines = ;
}
The line line in setup() throws an error.
I was wondering what is needed to add Linux support.
I have tried adding the native linux OpenCV library in the following path:
opencv_processing/library/linux/libopencv_java245.so
and everything seemed to worked correctly.
I guess the proper way of doing this would be to use the system's libopencv_java245.so
but some distributions do note have them in their repositories yet (e.g. Debian/Stable).
A part from this is there anything else missing for it to work on Linux?
Hi there,
I try to setup the openCV processing stuff, since it looks great.
Unfortunately on my linux system I face two troubles - maybe correlating to eclipse...
A) I am not able to embed/include the core.jar
-> where is it located, where can I download?
B) I am not familiar with the extension "*pde"
-> what is it good for?
-> which setting is good for syntax highlighting in eclipse?
-> while googling, I found the "eclipse pde" stuff, does this correlate?
Or am I totally mistaken?
Thanks,
günter
Need to be able to get it per-buffer. It should also have drawing methods, which means it'll need to be its own class.
It's quite useful: [Core#countNonZero](http://docs.opencv.org/java/org/opencv/core/Core.html#countNonZero(org.opencv.core.Mat)
In my draw() function I'm doing some preprocessing before I get the contours. For it I tell OpenCV to work in HSV color space. After it, I want to load the source image again and use the RGB color space, because it seems to work better to find contours. Here's the code:
src = loadImage("test.jpg");
size(src.width, src.height, P2D);
opencv = new OpenCV(this, src);
opencv.useColor(HSB);
opencv.setGray(opencv.getS().clone());
opencv.threshold(95);
opencv.erode();
processedImage = opencv.getSnapshot();
// Get Contours
contours = opencv.findContours(true, true);
contoursImage = opencv.getSnapshot();
// Get Canny Edges
opencv.loadImage(src);
opencv.useColor(RGB); // Change to RGB color space
opencv.findCannyEdges(20,75);
cannyImage = opencv.getSnapshot();
It works fine when working with a source image, but throws an exception when using the video from the webcam (Capture class):
java.lang.IndexOutOfBoundsException: Index: 3, Size: 1
With a source image the sketch output looks like:
Here the rest of the error:
java.lang.RuntimeException: java.lang.IndexOutOfBoundsException: Index: 3, Size: 1
at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:100)
at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:205)
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
at javax.media.opengl.Threading.invoke(Threading.java:191)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:483)
at processing.opengl.PGL.requestDraw(PGL.java:1149)
at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1604)
at processing.core.PApplet.run(PApplet.java:2176)
at java.lang.Thread.run(Thread.java:695)
Caused by: java.lang.IndexOutOfBoundsException: Index: 3, Size: 1
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at gab.opencv.OpenCV.ARGBtoBGRA(Unknown Source)
at gab.opencv.OpenCV.loadImage(Unknown Source)
at EdgesDetectionVideo.draw(EdgesDetectionVideo.java:44)
at processing.core.PApplet.handleDraw(PApplet.java:2305)
at processing.opengl.PGL$PGLListener.display(PGL.java:2601)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:588)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:572)
at javax.media.opengl.awt.GLCanvas$7.run(GLCanvas.java:1054)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1034)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:909)
at javax.media.opengl.awt.GLCanvas$8.run(GLCanvas.java:1065)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:715)
at java.awt.EventQueue.access$400(EventQueue.java:82)
at java.awt.EventQueue$2.run(EventQueue.java:676)
at java.awt.EventQueue$2.run(EventQueue.java:674)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:685)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
No errors are thrown. Output just ends up blank for some reason.
Hi. I'm trying to get convexity defects of a contour (in imgproc.java).
I added method to your Contour class to wrap it, but I'm getting an error (happens after a little while though). Any ideas much appreciated (or maybe you've already implemented this somewhere that I haven't come across?)
thanks!
In Contour Class:
(note: there's probably a more elegant way to form the int[][] but that shouldn't be a problem as far as I can see)
public int[][] getConvexityDefects(){
MatOfInt hull = new MatOfInt();
MatOfPoint points = new MatOfPoint(pointMat);
MatOfInt4 defects = new MatOfInt4();
Imgproc.convexHull(points, hull);
Imgproc.convexityDefects(points, hull, defects);
int[] defectsArray = defects.toArray();
int[][] d = new int[defects.height()][4];
int i = 0;
int i4 = 0;
while(i4 < defectsArray.length){
d[i][0] = defectsArray[i4];
d[i][1] = defectsArray[i4+1];
d[i][2] = defectsArray[i4+2];
d[i][3] = defectsArray[i4+3];
i++;
i4+=4;
}
return d;
}
The error:
OpenCV Error: Assertion failed (hull.checkVector(1, CV_32S) > 2) in convexityDefects, file /Users/matthewepler/opencv-2.4.5/modules/imgproc/src/contours.cpp, line 1971
Exception in thread "Animation Thread" CvException [org.opencv.core.CvException: /Users/matthewepler/opencv-2.4.5/modules/imgproc/src/contours.cpp:1971: error: (-215) hull.checkVector(1, CV_32S) > 2 in function convexityDefects
]
at org.opencv.imgproc.Imgproc.convexityDefects_0(Native Method)
at org.opencv.imgproc.Imgproc.convexityDefects(Imgproc.java:3182)
at gab.opencv.Contour.getConvexityDefects(Contour.java:109)
Is there a way to specify parameters using detect(), such as min neighbors, min face size, etc? And if not, how would I set these?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.