2

Hi I use OpenCV Java and have some problem.

I open video file and try get property like FPS. And others:

  • CV_CAP_PROP_POS_MSEC
  • CV_CAP_PROP_FRAME_COUNT

So first I opened video like this:

VideoCapture vC = new VideoCapture(url2);

and next i have a problem with function

vC.get(int i)

in OpenCV C++ its look like

vC.get(CV_CAP_PROP_FPS);

In Java where I find this constants?In HighGui I didnt find them. Only what I find is another libary to OpenCV where are this constants http://siggiorn.com/wp-content/uploads/libraries/opencv-java/docs/sj/opencv/Constants.CaptureProperty.html. But where I find them in OpenCV Java. Anyway how I have to use vC.get() function? Maybe some working example?

Aku
  • 200
  • 3
  • 9
  • 17
  • Not familiar with the library, shouldn't there be documentation on the function (or interface) to show what values for this `int` argument mean? Have you tried using the values contained in that other library to see if they do what you want? – Krease Jan 11 '14 at 19:39

3 Answers3

8

There is a bug report about this issue.

Until it is fixed, I suggest that you find these constants in the C++ source code, and define them yourself.

Edit:

I was just curious myself. You find them in the file modules/highgui/include/opencv2/highgui.hpp They are:

   CAP_PROP_POS_MSEC       =0,
   CAP_PROP_POS_FRAMES     =1,
   CAP_PROP_POS_AVI_RATIO  =2,
   CAP_PROP_FRAME_WIDTH    =3,
   CAP_PROP_FRAME_HEIGHT   =4,
   CAP_PROP_FPS            =5,
   CAP_PROP_FOURCC         =6,
   CAP_PROP_FRAME_COUNT    =7,
   CAP_PROP_FORMAT         =8,
   CAP_PROP_MODE           =9,
   CAP_PROP_BRIGHTNESS    =10,
   CAP_PROP_CONTRAST      =11,
   CAP_PROP_SATURATION    =12,
   CAP_PROP_HUE           =13,
   CAP_PROP_GAIN          =14,
   CAP_PROP_EXPOSURE      =15,
   CAP_PROP_CONVERT_RGB   =16,
   CAP_PROP_WHITE_BALANCE_BLUE_U =17,
   CAP_PROP_RECTIFICATION =18,
   CAP_PROP_MONOCROME     =19,
   CAP_PROP_SHARPNESS     =20,
   CAP_PROP_AUTO_EXPOSURE =21, // DC1394: exposure control done by camera, user can adjust refernce level using this feature
   CAP_PROP_GAMMA         =22,
   CAP_PROP_TEMPERATURE   =23,
   CAP_PROP_TRIGGER       =24,
   CAP_PROP_TRIGGER_DELAY =25,
   CAP_PROP_WHITE_BALANCE_RED_V =26,
   CAP_PROP_ZOOM          =27,
   CAP_PROP_FOCUS         =28,
   CAP_PROP_GUID          =29,
   CAP_PROP_ISO_SPEED     =30,
   CAP_PROP_BACKLIGHT     =32,
   CAP_PROP_PAN           =33,
   CAP_PROP_TILT          =34,
   CAP_PROP_ROLL          =35,
   CAP_PROP_IRIS          =36,
   CAP_PROP_SETTINGS      =37
Matthias
  • 817
  • 2
  • 7
  • 14
  • 1
    To use, seems you'll have to recompile. You can't just call: aVideoCapture.cap.get( valueOfTheConstantHere). In the link @Matthias included, 'Peter Meier' reports that after he "recompiled the whole thing" the constant 'CV_CAP_PROP_FRAME_COUNT' worked, whereas trying it without the recompile gives error: "HIGHGUI ERROR: V4L2: Unable to get property (7) - Invalid argument" (Same error for other constants tried) – Matt S. Dec 26 '14 at 12:24
3

use class import org.opencv.videoio.Videoio;

vc.open(FD.class.getResource("1.avi").getPath());
double totalFrameNumber = vc.get(Videoio.CAP_PROP_FRAME_COUNT);  
System.out.println("\n"+totalFrameNumber);
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59
曹明生
  • 31
  • 1
0

It seems the bug is solved. Now you should be able to use it as:

VideoCapture vC = new VideoCapture(...);
nbFrames = vC.get(Videoio.CAP_PROP_FRAME_COUNT);
ilke444
  • 2,641
  • 1
  • 17
  • 31
  • I have tried like this. but it is not working. Can you help me please? _VideoCapture capture = new VideoCapture("/home/aritra/workspace/oopencv/horror.mp4"); if(!capture.isOpened()){ System.out.println("could not open this file "); } else{ System.out.println("lingth"+(capture.get(Videoio.CAP_PROP_FRAME_COUNT)));_ – Yonex Oct 03 '17 at 15:23