I would like to save a file (avi) of some frames (in this case, 600) from my webcam using java opencv, but i have no idea how to do that, the code below gives me the avi file specified but with size 0, no frames inside whatsover, also in the directory i have those 600 frames in jpeg's.
It's important to use java for that, no python.
Mat frame = new Mat();
VideoWriter writer = new VideoWriter("c:/opencv/vid.avi", VideoWriter.fourcc('X','2','6','4'), 30 ,frame.size(), true);
videoCapture = new VideoCapture();
videoCapture.open(0);
videoCapture.set(Videoio.CAP_PROP_FRAME_WIDTH, 1280);
videoCapture.set(Videoio.CAP_PROP_FRAME_HEIGHT, 720);
while (true){
videoCapture.read(frame);
if (!frame.empty())
break;
}
int frameNo = 0;
while (frameNo < 600){
videoCapture.read(frame);
writer.write(frame);
Imgcodecs imageCodecs = new Imgcodecs();
String file = "c:/opencv/i" + frameNo + ".jpg";
Imgcodecs.imwrite(file,frame);
frameNo++;
}
videoCapture.release(); // release device
frame.size()what is frame, how did you initialize it. That sizes should be equal to resolution(width and height) which is desired video size.