i have just started to learn openCV in java and i have setup my Eclipse IDE with all OpenCV java dependencies.
Now i have a task in hand to extract a single frame from a video file which i have recorded in .avi file format.
i searched from this link and used the code given there as below,
package vasanth;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;
public class Vasanth {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture camera = new VideoCapture("G:\\PICTURES\\roxtar vassy\\early days in APSCE.wmv");
/* if(!camera.isOpened()){
System.out.println("Error");
} */
Mat frame = new Mat();
while(true){
System.out.println("Looping.. \n");
if (camera.read(frame)){
System.out.println("Frame Obtained");
System.out.println("Captured Frame Width " +
frame.width() + " Height " + frame.height());
Highgui.imwrite("camera.jpg", frame);
System.out.println("OK");
break;
}
}
}
}
when i execute this, the program is looping at inifinitely at this line
camera.read(frame)
i also tried running this code without he loop and was successfully in getting the camera.jpg file on my system but the file was corrupted. I understand that this frame was not completely extracted with all the pixels and hence seems corrupted.
So the problem here is why does camera.read(frame) this always return false and the loop never breaks?
I have waited for more than 10 minutes. All i want to do is extract one single frame and it is not happening with this method.
As per what i have searched on google i understant there is a tool called ffmpeg which takes a video file as input and give me frames. But i want to achieve this functionality with my own java code running on Eclipse for starters.