bytedeco / javacv-examples Goto Github PK
View Code? Open in Web Editor NEWExamples of using JavaCV / OpenCV library on Java Virtual Machine
Examples of using JavaCV / OpenCV library on Java Virtual Machine
I need to get the minimum enclosing circle of the largest contour from my binary image.
I have found largest contour but unable to get the enclosing circle.
C++ function defines as:
minEnclosingCirlce( InputArray points, Point2f center, float radius )
I have the contour as cvSeq.
OpenCV says:
org.bytedeco.javacpp.opencv_imgproc.minEnclosingCircle(@ByVal Mat arg0, @ByRef Point2f arg1, @ByRef FloatPointer arg2)
Now i need to convert the cvSeq contour to Mat / Iplimage
Please help
In chapter02,Ex2ColorReduce,when I run the example code, I received this error:
[info] running (fork) opencv_cookbook.chapter02.Ex2ColorReduce
[error] Exception in thread "main" java.lang.IndexOutOfBoundsException: 518400
[error] at org.bytedeco.javacpp.indexer.Indexer.checkIndex(Indexer.java:101)
[error] at org.bytedeco.javacpp.indexer.UByteRawIndexer.getRaw(UByteRawIndexer.java:73)
[error] at org.bytedeco.javacpp.indexer.UByteRawIndexer.get(UByteRawIndexer.java:76)
[error] at opencv_cookbook.chapter02.Ex2ColorReduce$.$anonfun$colorReduce$1(Ex2ColorReduce.scala:48)
[error] at opencv_cookbook.chapter02.Ex2ColorReduce$.$anonfun$colorReduce$1$adapted(Ex2ColorReduce.scala:46)
[error] at scala.collection.immutable.Range.foreach(Range.scala:190)
[error] at opencv_cookbook.chapter02.Ex2ColorReduce$.colorReduce(Ex2ColorReduce.scala:46)
[error] at opencv_cookbook.chapter02.Ex2ColorReduce$.delayedEndpoint$opencv_cookbook$chapter02$Ex2ColorReduce$1(Ex2ColorReduce.scala:28)
[error] at opencv_cookbook.chapter02.Ex2ColorReduce$delayedInit$body.apply(Ex2ColorReduce.scala:22)
[error] at scala.Function0.apply$mcV$sp(Function0.scala:39)
[error] at scala.Function0.apply$mcV$sp$(Function0.scala:39)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
[error] at scala.App.$anonfun$main$1(App.scala:76)
[error] at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error] at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
[error] at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
[error] at scala.collection.AbstractIterable.foreach(Iterable.scala:926)
[error] at scala.App.main(App.scala:76)
[error] at scala.App.main$(App.scala:74)
[error] at opencv_cookbook.chapter02.Ex2ColorReduce$.main(Ex2ColorReduce.scala:22)
[error] at opencv_cookbook.chapter02.Ex2ColorReduce.main(Ex2ColorReduce.scala)
Hello there,
Thank you for the good work on writing this examples - they do help in understanding of javacpp interface to OpenCV library.
I noticed in the commits that you refactored example to work with OpenCV 3. Could you also change readme and the folder name? It will make it more attractive, I think.
Best,
Mikhail
Using following code from the examples but the following error is being thrown, any one got any ideas how to solve this ?
def drawContours(image: IplImage, contours: Seq[CvSeq]): IplImage = {
contours.foreach(cvDrawContours(image, _, colourRandom, colourRandom, -1, 1, CV_AA, cvPoint(0, 0)))
image
}
overloaded method value cvDrawContours with alternatives:
[error] (x$1: org.bytedeco.javacpp.helper.opencv_core.CvArr,x$2: org.bytedeco.javacpp.opencv_core.CvSeq,x$3: org.bytedeco.javacpp.opencv_core.CvScalar,x$4: org.bytedeco.javacpp.opencv_core.CvScalar,x$5: Int,x$6: Int,x$7: Int,x$8: Array[Int])Unit <and>
[error] (x$1: org.bytedeco.javacpp.helper.opencv_core.CvArr,x$2: org.bytedeco.javacpp.opencv_core.CvSeq,x$3: org.bytedeco.javacpp.opencv_core.CvScalar,x$4: org.bytedeco.javacpp.opencv_core.CvScalar,x$5: Int,x$6: Int,x$7: Int,x$8: java.nio.IntBuffer)Unit <and>
[error] (x$1: org.bytedeco.javacpp.helper.opencv_core.CvArr,x$2: org.bytedeco.javacpp.opencv_core.CvSeq,x$3: org.bytedeco.javacpp.opencv_core.CvScalar,x$4: org.bytedeco.javacpp.opencv_core.CvScalar,x$5: Int,x$6: Int,x$7: Int,x$8: org.bytedeco.javacpp.opencv_core.CvPoint)Unit
[error] cannot be applied to (org.bytedeco.javacpp.opencv_core.IplImage, org.bytedeco.javacpp.opencv_core.CvSeq, org.bytedeco.javacpp.opencv_core.Scalar, org.bytedeco.javacpp.opencv_core.Scalar, Int, Int, Int, org.bytedeco.javacpp.opencv_core.CvPoint)
[error] contours.foreach(cvDrawContours(image, _, colourRandom, colourRandom, -1, 1, CV_AA, cvPoint(0, 0)))
Examples in chapter11 can not run properly under ubuntu 16.04 or windows7, just showing the errror "failed to open input video", any suggestion?
Thanks!
[info] Running opencv2_cookbook.chapter11.Ex1ReadVideoSequence
[error] Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Failed to open input video
[error] at scala.Predef$.require(Predef.scala:277)
[error] at opencv2_cookbook.chapter11.Ex1ReadVideoSequence$.delayedEndpoint$opencv2_cookbook$chapter11$Ex1ReadVideoSequence$1(Ex1ReadVideoSequence.scala:29)
[error] at opencv2_cookbook.chapter11.Ex1ReadVideoSequence$delayedInit$body.apply(Ex1ReadVideoSequence.scala:23)
[error] at scala.Function0.apply$mcV$sp(Function0.scala:34)
[error] at scala.Function0.apply$mcV$sp$(Function0.scala:34)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
[error] at scala.App.$anonfun$main$1$adapted(App.scala:76)
[error] at scala.collection.immutable.List.foreach(List.scala:378)
[error] at scala.App.main(App.scala:76)
[error] at scala.App.main$(App.scala:74)
[error] at opencv2_cookbook.chapter11.Ex1ReadVideoSequence$.main(Ex1ReadVideoSequence.scala:23)
[error] at opencv2_cookbook.chapter11.Ex1ReadVideoSequence.main(Ex1ReadVideoSequence.scala)
java.lang.RuntimeException: Nonzero exit code returned from runner: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code returned from runner: 1
[error] Total time: 11 s, completed 2017-2-10 14:32:44
sbt:opencv2_cookbook>
@jpsacha ,i have trying to execute pylon by using javacpp but it's shows an error like:
ERROR] Failed to execute goal on project pylon-platform: Could not resolve dependencies for project org.bytedeco:pylon-platform:jar:1.0-1.5.1-SNAPSHOT: The following artifacts could not be resolved: org.bytedeco:Pylon:jar:1.0-1.5.1-SNAPSHOT, org.bytedeco:Pylon:jar:linux-x86_64:1.0-1.5.1-SNAPSHOT: Failure to find org.bytedeco:Pylon:jar:1.0-1.5.1-SNAPSHOT in https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles
Hello. I'm getting this from cd FlyCapture2-demo & sbt example_ui/run
:
[info] 0 [main] ERROR flycapture.examples.cpp.snap.FlyCaptureSnapApp$ - Default handler caught exception: Exception in Application start method
[info] java.lang.RuntimeException: Exception in Application start method
[info] at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
[info] at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
[info] at java.lang.Thread.run(Thread.java:748)
[info] Caused by: java.lang.UnsatisfiedLinkError: no jniFlyCapture2 in java.library.path
[info] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
[info] at java.lang.Runtime.loadLibrary0(Runtime.java:870)
[info] at java.lang.System.loadLibrary(System.java:1122)
[info] at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:654)
[info] at org.bytedeco.javacpp.Loader.load(Loader.java:492)
[info] at org.bytedeco.javacpp.Loader.load(Loader.java:409)
[info] at org.bytedeco.javacpp.FlyCapture2.<clinit>(FlyCapture2.java:10)
[info] at java.lang.Class.forName0(Native Method)
[info] at java.lang.Class.forName(Class.java:348)
[info] at org.bytedeco.javacpp.Loader.load(Loader.java:464)
[info] at org.bytedeco.javacpp.Loader.load(Loader.java:409)
[info] at org.bytedeco.javacpp.FlyCapture2$FC2Version.<clinit>(FlyCapture2.java:709)
[info] at flycapture.examples.cpp.snap.SnapModel.<init>(SnapModel.scala:73)
[info] at flycapture.examples.cpp.snap.FlyCaptureSnapApp$.delayedEndpoint$flycapture$examples$cpp$snap$FlyCaptureSnapApp$1(FlyCaptureSnapApp.scala:41)
[info] at flycapture.examples.cpp.snap.FlyCaptureSnapApp$delayedInit$body.apply(FlyCaptureSnapApp.scala:32)
[info] at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
[info] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
[info] at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
[info] at scalafx.application.JFXApp$$anonfun$init$1.apply(JFXApp.scala:297)
[info] at scala.collection.immutable.List.foreach(List.scala:381)
[info] at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
[info] at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
[info] at scalafx.application.JFXApp$class.init(JFXApp.scala:297)
[info] at flycapture.examples.cpp.snap.FlyCaptureSnapApp$.init(FlyCaptureSnapApp.scala:32)
[info] at scalafx.application.AppHelper.start(AppHelper.scala:33)
[info] at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
[info] at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
[info] at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
[info] at java.security.AccessController.doPrivileged(Native Method)
[info] at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
[info] at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
[info] at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
[info] at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
[info] ... 1 more
[info] Caused by: java.lang.UnsatisfiedLinkError: /tmp/javacpp1455675293976712/libjniFlyCapture2.so: libflycapture.so.2: cannot open shared object file: No such file or directory
[info] at java.lang.ClassLoader$NativeLibrary.load(Native Method)
[info] at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
[info] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
[info] at java.lang.Runtime.load0(Runtime.java:809)
[info] at java.lang.System.load(System.java:1086)
[info] at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:637)
[info] ... 30 more
Using OpenJDK 8 / OpenJFX 8 / Debian Stretch / amd64 (platform
in the sbt build reports linux-x86_64
, which is correct). Any ideas?
While trying to incorporate histogram calculation in another framework, I've been getting errors like error: (-215:Assertion failed) j < nimages in function 'histPrepareImages'
and I couldn't figure out why.
Trying out the Cookbook's example code, namely Ex2ComputeHistogramGraphJava.java, I've come across a peculiar behavior:
The following code works:
Mat src = loadAndShowOrExit(new File("data/group.jpg"), IMREAD_GRAYSCALE);
// Calculate histogram
Histogram1DJava h = new Histogram1DJava();
BufferedImage histogram = h.getHistogramImage(src);
// Display the graph
show(histogram, "Histogram");
Swapping out the loadAndShowOrExit(...)
call with a plain imread(...)
one (which loadAndShowOrExit
essentially uses under the hood), then it doesn't work:
Mat src = imread("data/group.jpg", IMREAD_GRAYSCALE);
// Calculate histogram
Histogram1DJava h = new Histogram1DJava();
BufferedImage histogram = h.getHistogramImage(src);
// Display the graph
show(histogram, "Histogram");
The imread
-based code results in this error:
An exception occurred while executing the Java class. OpenCV(4.6.0) /__w/javacpp-presets/javacpp-presets/opencv/cppbuild/linux-x86_64/opencv-4.6.0/modules/imgproc/src/histogram.cpp:160: error: (-215:Assertion failed) j < nimages in function 'histPrepareImages'
Is is necessary to call some initialization methods first? If so, that wasn't apparent from the code examples on javacv.
I've attached a minimal Maven project which contains the original Ex2ComputeHistogramGraphJava
class and the failing Ex2bComputeHistogramGraphJava
one. You can switch which class is being executed in the pom.xml
file by changing the mainClass
option.
You can execute the project on the command-line using mvn exec:java
.
openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu120.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu120.04, mixed mode, sharing)
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Java version: 11.0.16, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_NZ, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-131-generic", arch: "amd64", family: "unix"
Linux metal 5.4.0-131-generic #147-Ubuntu SMP Fri Oct 14 17:07:22 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
I would like to propose an tips about the flandmark-demo.
I'm cannot to compile in C++ the flandmarks ( very difficult) to generates .dll to afterwards running bytedeco JNA/JNI from flandmarks
I think very difficulty to compile this framework, or at least you provide an .dll to use the demonstration (integrated JAVA with flandmarks .dll)
Thanks
Hi,
I cloned the javacv-examples project and tried running the first example within SBT. The code compiled and all repo's were resolved but am getting the following error when running the example.
[info] Running opencv2_cookbook.chapter01.Ex1MyFirstOpenCVApp
[error] Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path
[error] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
[error] at java.lang.Runtime.loadLibrary0(Runtime.java:870)
[error] at java.lang.System.loadLibrary(System.java:1122)
[error] at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:536)
[error] at org.bytedeco.javacpp.Loader.load(Loader.java:411)
[error] at org.bytedeco.javacpp.Loader.load(Loader.java:354)
[error] at org.bytedeco.javacpp.opencv_core.<clinit>(opencv_core.java:10)
[error] at java.lang.Class.forName0(Native Method)
[error] at java.lang.Class.forName(Class.java:348)
[error] at org.bytedeco.javacpp.Loader.load(Loader.java:386)
[error] at org.bytedeco.javacpp.Loader.load(Loader.java:354)
[error] at org.bytedeco.javacpp.opencv_highgui.<clinit>(opencv_highgui.java:13)
[error] at opencv2_cookbook.chapter01.Ex1MyFirstOpenCVApp$.delayedEndpoint$opencv2_cookbook$chapter01$Ex1MyFirstOpenCVApp$1(Ex1MyFirstOpenCVApp.scala:22)
[error] at opencv2_cookbook.chapter01.Ex1MyFirstOpenCVApp$delayedInit$body.apply(Ex1MyFirstOpenCVApp.scala:19)
[error] at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
[error] at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
[error] at scala.App$$anonfun$main$1.apply(App.scala:76)
[error] at scala.App$$anonfun$main$1.apply(App.scala:76)
[error] at scala.collection.immutable.List.foreach(List.scala:381)
[error] at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
[error] at scala.App$class.main(App.scala:76)
[error] at opencv2_cookbook.chapter01.Ex1MyFirstOpenCVApp$.main(Ex1MyFirstOpenCVApp.scala:19)
[error] at opencv2_cookbook.chapter01.Ex1MyFirstOpenCVApp.main(Ex1MyFirstOpenCVApp.scala)
[error] Caused by: java.lang.UnsatisfiedLinkError: /tmp/javacpp20650280539170/libjniopencv_core.so: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /tmp/javacpp20650280539170/libopencv_core.so.2.4)
[error] at java.lang.ClassLoader$NativeLibrary.load(Native Method)
[error] at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
[error] at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1822)
[error] at java.lang.Runtime.load0(Runtime.java:809)
[error] at java.lang.System.load(System.java:1086)
[error] at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:525)
[error] ... 19 more
Here you saying "Smaller boilerplate code makes examples easier to read and understand". It's not true. I don't know scala and I bet most JVM-based code is on Java. In order to understand your example I have to learn scala first, which I don't want to.
And I'm really wondering why JavaCV has examples in Scala. Then you need to call it ScalaCV. Even Lightbend Akka documentation has examples in Scala and Java.
Dear Team,
when final CvHaarClassifierCascade faceCascade = cvLoadHaarClassifierCascade(file.getCanonicalPath(), cvSize(0, 0)); line is executing i got below exception
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.opencv_core
please help
Hello,
I am working on windows 7 platform with jdk1.8, I am getting following error. I tried a lot but unable to find the reason why getting this error, error snap is as follows.
Exception in thread "main" java.lang.NoSuchMethodError: putMemberOffset
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:637) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:637)
at org.bytedeco.javacpp.Loader.load(Loader.java:492)
at org.bytedeco.javacpp.Loader.load(Loader.java:409)
at org.bytedeco.javacpp.opencv_core.(opencv_core.java:10)
at detection.Example1.loadFaceCascade(Example1.java:36)
at detection.Example1.main(Example1.java:140)
Error getting static method ID of org/bytedeco/javacpp/Loader/putMemberOffset
Please help me!
I added following libraries in project.
opencv-3.0.0-1.0.jar
opencv-3.0.0-1.0-windows-x86.jar
opencv-3.0.0-1.0-windows-x86_64.jar
javacpp-1.0.jar
javacv-1.0.jar
Also tried different versions of these libraries but not worked out.
[info] Running opencv2_cookbook.chapter11.Ex3WriteVideoSequence
[info] Processing video file: /Users/ankurjain/Downloads/javacv-examples-22ef77c9ed889b9cf66ecc8f1972311966b2f1bd/OpenCV2_Cookbook/data/bike.avi
[info] Processing video file: /Users/ankurjain/Downloads/javacv-examples-22ef77c9ed889b9cf66ecc8f1972311966b2f1bd/OpenCV2_Cookbook/bikeOut.avi
[info]
[info] Video processing done.
The resulting bikeOut.avi is an empty file.
I tried a similar code for writing a single frame to a video file and that also gives an empty file. I don't see any other errors.
{
val imagePath = getClass.getResource("/IMG_20170221_161618.jpg").getPath
val origImage = imread(imagePath)
val writer = createWriter()
writeNextFrame(writer, origImage)
writeNextFrame(writer, origImage)
writeNextFrame(writer, origImage)
writer.foreach(_.release())
}
def createWriter(): Option[VideoWriter] = {
val writer = new VideoWriter()
val actualFrameRate = 1
val actualCodec = VideoWriter.fourcc('M', 'P', 'E', 'G')
if (writer.open("abc.mpeg", actualCodec, actualFrameRate, new Size(3456, 4608), true)) {
Some(writer)
} else {
None
}
}
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.