How to open and process a video file like .mpeg or .avi using openCV's VideoCapture method in Java -
import org.opencv.core.core; import org.opencv.core.mat; import org.opencv.core.size; import org.opencv.highgui.highgui; import org.opencv.highgui.videocapture; import org.opencv.imgproc.imgproc; public class video { public static void main(string[] args) { system.loadlibrary(core.native_library_name); videocapture cap = new videocapture(0); cap.open(1); if(!cap.isopened()) { system.out.println("no camera"); } else { system.out.println("yes. camera"); } mat frame = new mat(); cap.retrieve(frame); highgui.imwrite("me1.jpg", frame); mat frameblur = new mat(); imgproc.blur(frame, frameblur, new size(5,5)); highgui.imwrite("me2-blurred.jpg", frameblur); imgproc.gaussianblur(frame, frameblur, new size(25, 25), 20); highgui.imwrite("me3-blurred.jpg", frameblur); cap.release(); } }
i have used code open camera device , capture 3 different frames , made operations on it. but, couldn't open file .avi/.mpg/.mp4 etc., using {n_open} method of videocapture. there method in videocapture implementation here. because private , native method, method can't accesses using videocapture's object.
could 1 how using pure opencv 2.4.6 , java
(please dont suggest solution using processing libraries)
take on opencv 2.4.8
. videocapture
api has been extended of public videocapture(string filename)
method. question remains why feature has been implemented late.
if using of recent version of opencv isn't acceptable reason, have several options:
rebuild opencv method marked public
hacky one: make copy of videocapture class (or extend original 1 , play reflection) public
videocapture(string)
constructor. give support native methodprivate static native long n_videocapture(java.lang.string filename)
creating own dll using c++ opencv api. (tested!)
Comments
Post a Comment