score:1
there are couple of issues i faced while reproducing your issue, so let me guide you through them.
first of all, you use the old version of the framework. the current one is 3.2, so consider upgrading. i used the newest version.
you should not comment out the
camera.isopened()
check since if the camera is not opened there is no sense to proceed. i assume, that your app couldn't pass that check, so you decided to skip that :) but in order to open the camera properly you should either do this or this. the first link worked for me (the only change is that for 3.2 version the path is\opencv\build\x64\vc14\bin
and i had to reboot computer)
the code is pretty much the same as you have so far with only difference for the latest version:
import org.opencv.core.core;
import org.opencv.core.mat;
import org.opencv.imgcodecs.imgcodecs;
import org.opencv.videoio.videocapture;
import javax.swing.*;
import java.awt.image.bufferedimage;
import java.awt.image.databufferbyte;
import java.awt.image.writableraster;
import java.nio.file.paths;
public class vasanth {
public static void main(string[] args) {
system.loadlibrary(core.native_library_name);
string filepath = "g:\\pictures\\roxtar vassy\\early days in apsce.wmv";
if (!paths.get(filepath).tofile().exists()){
system.out.println("file " + filepath + " does not exist!");
return;
}
videocapture camera = new videocapture(filepath);
if (!camera.isopened()) {
system.out.println("error! camera can't be opened!");
return;
}
mat frame = new mat();
while(true){
if (camera.read(frame)){
system.out.println("frame obtained");
system.out.println("captured frame width " +
frame.width() + " height " + frame.height());
imgcodecs.imwrite("camera.jpg", frame);
system.out.println("ok");
break;
}
}
bufferedimage bufferedimage = mattobufferedimage(frame);
showwindow(bufferedimage);
camera.release();
}
private static bufferedimage mattobufferedimage(mat frame) {
int type = 0;
if (frame.channels() == 1) {
type = bufferedimage.type_byte_gray;
} else if (frame.channels() == 3) {
type = bufferedimage.type_3byte_bgr;
}
bufferedimage image = new bufferedimage(frame.width(), frame.height(), type);
writableraster raster = image.getraster();
databufferbyte databuffer = (databufferbyte) raster.getdatabuffer();
byte[] data = databuffer.getdata();
frame.get(0, 0, data);
return image;
}
private static void showwindow(bufferedimage img) {
jframe frame = new jframe();
frame.getcontentpane().add(new jlabel(new imageicon(img)));
frame.setdefaultcloseoperation(windowconstants.exit_on_close);
frame.setsize(img.getwidth(), img.getheight() + 30);
frame.settitle("image captured");
frame.setvisible(true);
}
}
note, that in order to demonstrate that this piece of code works i use simple swing jframe:
score:0
i was facing the same issue which is camera.isopened() returning false. this is how i resolved it.
string filepath = "c:\\aslam_face_detection.mp4";
videocapture camera = new videocapture(filepath);
camera.open(filepath); // this is the line i added
camera.isopened(); // returns true. worked.
Source: stackoverflow.com
Related Query
- Java - Reading a frame in OpenCV
- java code for reading image instead of getting frame
- Java OpenCV - org.opencv.core.Core rectangle() method missing
- Using OpenCV in Java with JavaCV
- How to configure opencv in Eclipse for Java developers with plugin CDT?
- adding openCV to java buildpath in eclipse
- Java console not reading in Chinese characters correctly
- Eclipse Java OpenCV unsatisfiedLinkError in Test src folder only
- reading environment variables from java using Eclipse
- Java IO: Why does the numerical representation of line feed appear on the console when reading from stdin?
- Reading SVN (Subclipse) rev number from java code
- Java & OpenCV can't convert RGB .gif image to GRAY
- Running opencv using java error
- Urdu file reading in java
- Eclipse : Java : OpenCV : "The import org cannot be resolved."
- OpenCV capture loops video/Does not detect last frame
- Reading .xlsx in java
- Reading .txt File From Relative Path in Java
- How to Draw multiple rectangles on a frame on Touch in OpenCV for Android?
- Reading Resources correctly in Eclipse with Java
- Reading Manifest.mf in war file using java
- Java verify error Expected stackmap frame
- Java Spring boot application with OpenCv : UnsatisfiedLinkError under Eclipse if use spring-boot-devtools
- Java program Opencv unsatisfiedlinkerror
- Can we run opencv java on android?
- How can I do Asynchronous messaging while reading and processing of the database records by using Java
- Java - File Reading after exporting to executable jar file in eclipse
- Reading a Txt-File in a jar-File in Java
- UnsatisfiedLinkError Trying to run OpenCV java code cross compiled
- Java reading image but returning null
More Query from same tag
- How to display different strings on button click
- code works in eclipse but not in command line
- Inserting data into a database using servlet returns a blank page
- How can I fix the project build path error? I can't import the java.lang.math for a Java 8/9 Calculator app
- Having trouble getting a library working in an eclipse project
- Problems getting HelloWorld for Mule to work
- PyDev paste to console with blank lines
- How to ad an effect to an ImageButton on an android app?
- Why does Spark application work in spark-shell but fail with "org.apache.spark.SparkException: Task not serializable" in Eclipse?
- Why doesn't Eclipse generate javadoc for all classes
- Eclipse Color Theme is not working
- How do I run multiple instances of a JMS program in Eclipse?
- Issues while executing jar using command line in ubuntu
- Ubuntu Subversion with Windows Client
- wso2 xpath expression in property mediator doesn't work
- Eclipse PDT, PHPUnit autocomplete
- How can I create a root folder for my projects in Eclipse as recommended by EGit?
- JPA Join Prints to many Results
- I cant find the Plugin Project in my newly installed Eclipse? Help
- Eclipse template for wrapping an iterable selection in a for each loop
- Annoying error dialog box when eclipse output-console scrolls. What's causing it?
- java.lang.NoClassDefFoundError: com.google.android.gms.gcm.GoogleCloudMessaging using java.lang.NoClassDefFoundError:
- Change Eclipse tab to correctly indent line as Emacs does
- Previous Blackberry Plugin for Eclipse
- Cannot create JavaFX project in Eclipse Kepler
- Can't deploy a jar on Jboss EAP6 with error java.lang.NoClassDefFoundError
- How to select marker entry from Markers view
- App Development using eclipse
- Eclipse OpenCV Undefined reference and Binary not found
- Egit plugin configuration for pushing the existing project