opencv-java / getting-started Goto Github PK
View Code? Open in Web Editor NEWGetting started with OpenCV and JavaFX
Getting started with OpenCV and JavaFX
Hey @luigidr
at FXHelloCVController.java Lines 160-168 you convert a mat to a JavaFX Image. Sometimes this fct (random time) will not convert a mat correctly and the ImageViewer stops working(Will not receive a correct image anymore). Atm i dont know why, but i will find it out. I found this code which works well and is more performant.
http://stackoverflow.com/questions/29120869/how-to-convert-matopencv-to-imagejavafx
Performance: Mat -> BufferedImage -> JavaFXImage http://cell0907.blogspot.de/2013/12/from-mat-to-bufferedimage.html
-->
private Image mat2Image(Mat frame) {
try{
return SwingFXUtils.toFXImage(matToBufferedImage(frame),null);
} catch (Exception e) {
System.out.println("Cant convert mat");
return null;
}
}
public BufferedImage matToBufferedImage(Mat matBGR){
int width = matBGR.width(), height = matBGR.height(), channels = matBGR.channels() ;
byte[] sourcePixels = new byte[width * height * channels];
matBGR.get(0, 0, sourcePixels);
//TYPE_BYTE_GRAY - gray images , TYPE_3BYTE_BGR - 3 Channles
image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
System.arraycopy(sourcePixels, 0, targetPixels, 0, sourcePixels.length);
return image;
}
I am trying to display IplImage on imageview in application. But Imageview_id.setImage() allows only Image obj as parameter. Is there is another method to display iplImage in imageview ? or How to convert IplImage to Image?
The setFrametoImageView()
and updateUIObjects()
method could be replaced by a single method that uses generics to avoid code duplication.
Errors in FXHelloCVController.java
Image imagetoshow = Utils.mat2Image(frame);
updateImageView(currentFrame, imagetoshow);
Error: The method mat2Image(Mat) is undefined for the type Utils
private void updateImageView(ImageView view, Image image){
Utils.onFXThread(view.imageProperty(), image);
Error : The method onFXThread(ObjectProperty, Image) is undefined for the type Utils
I have done everything according to the doc.I can find a file named libopencv_java310.so in /path/to/opencv-3.1.0/build/lib.
Also ,I configured the Native library path to /path/to/opencv-3.1.0/build/lib in eclipse.
but after running he HelloCV project,an error below occured:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path.
There is a huge memory leak here. Im trying to fix, but even calling Mat.release(), didn't worked. I think may there is an issue calling read(Mat mat) from another thread.
private Mat grabFrame()
{
// init everything
Mat frame = new Mat();
// check if the capture is open
if (this.capture.isOpened())
{
try
{
// read the current frame
this.capture.read(frame);
// if the frame is not empty, process it
if (!frame.empty())
{
Imgproc.cvtColor(frame, frame, Imgproc.COLOR_BGR2GRAY);
}
}
catch (Exception e)
{
// log the error
System.err.println("Exception during the image elaboration: " + e);
}
}
return frame;
}
Hi, I have used netbeans instead of eclipse for the project, but I have followed everything mentioned in the tutorial. Yet I get a "Location is not set" error, and here is a printscreen of what I am seeing exactly. Can I know why is the error being caused since I do not really get it and how can it be fixed.
Edited: I have created another package for the utils.Utils but I assume that has nothing to do with it.
Generally, it is "better" to prefer the Java Executor
to classical Thread
.
If possible, replace the processFrame
thread with an Executor
object or with a JavaFX object suitable for concurrency (i.e., from javafx.concurrent
).
FXHelloCVController.java Line 72. It's not allowed to set a new Image (ImageViewer) from another Thread(Runnable).
Possible fix:
FXHelloCVController.java Line72
setFrametoImageView(imageToShow) instead of currentFrame.setImage(imageToShow);
FXHelloCVController.java Line 113
private void setFrametoImageView(Image frame){
Platform.runLater(() -> {
currentFrame.setImage(frame);
//set Image height/width by window size
});
}
The FPS calculation present in the application doesn't work with the latest version of Java 8/JavaFX/OpenCV 3.1. It always shows "0.0".
It seems that, for live videos, the method used in the code doesn't work (it should work for "offline" videos). Amend or remove the FPS calculation.
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.