Accessing webcam using javacv

Configuration steps for javacv on Eclipse running on windows 7 can be found in the link below.
http://opencvlover.blogspot.in/2012/04/javacv-setup-with-eclipse-on-windows-7.html

Instructions for importing video in javacv can be found in link below
http://opencvlover.blogspot.in/2012/05/importing-video-using-javacv.html

Accessing webcam using javacv is pretty much similar to importing video. We just have to set null parameter  while specifying video path in deceleration of OpenCVFramegrabber. Also we have to flip output from webcam horizontally to get it like mirror.

Following is the code snippet which uses OpenCVFrameGrabber to capture from webcam.


16 comments:

  1. errors dude

    ERROR: SampleCB() - buffer sizes do not match
    ERROR: SampleCB() - buffer sizes do not match
    ERROR: SampleCB() - buffer sizes do not match
    ERROR: SampleCB() - buffer sizes do not match

    repeated and when i close below comes

    ERROR: S#
    # A fatal error has been detected by the Java Runtime Environment:
    #
    # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x682f17bc, pid=1448, tid=5664
    #
    # JRE version: 7.0_17-b02
    # Java VM: Java HotSpot(TM) Client VM (23.7-b01 mixed mode, sharing windows-x86 )
    # Problematic frame:
    # C [quartz.dll+0x117bc] DllGetClassObject+0x8558
    #
    # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
    #
    # An error report file with more information is saved as:
    # F:\eclipse workspace\webcam\hs_err_pid1448.log
    #
    # If you would like to submit a bug report, please visit:
    # http://bugreport.sun.com/bugreport/crash.jsp
    #

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.


      JavaEE Training in Chennai JavaEE Training in Chennai

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training Core Java 8 Training in Chennai Java 8 Training in Chennai

      Delete
  2. I got:
    Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:174)
    at Webcam.main(Webcam.java:22)
    Caused by: java.lang.IllegalStateException: Can't overwrite cause
    at java.lang.Throwable.initCause(Throwable.java:456)
    at com.googlecode.javacpp.Loader.load(Loader.java:581)
    at com.googlecode.javacpp.Loader.load(Loader.java:532)
    at com.googlecode.javacv.cpp.opencv_highgui.(opencv_highgui.java:79)
    ... 2 more

    ReplyDelete
  3. this code is correct but i want to increase the resolution of 1080X640 how can i change this ..please help me .............

    ReplyDelete
    Replies
    1. This code uses default resolution of image provided by your camera. If you want to set resolution manually then just set desired resolution in function canvas.setCanvasSize()

      Delete
  4. It's really an informative and well described post. I appreciate your topic for blogging. Thanks for sharing such a use ful post.


    www.visec.net/index.php Watch your Home or office,Video Surveillance,Web cam surveillance, Live video of your home, protect family, surveillance software.

    ReplyDelete
  5. how to make .jar file with this code? I tried, but when i double click the .jar file it didn't open and not showing the video from webcam.

    ReplyDelete
  6. VIDIOC_QUERYMENU: Invalid argument
    VIDIOC_QUERYMENU: Invalid argument
    VIDIOC_QUERYMENU: Invalid argument
    HIGHGUI ERROR: V4L: Property (16) not supported by device

    ReplyDelete
  7. how you are converting Frame to an IplImage in line 30, as u r grabbing a frame and saving it to IplImage

    ReplyDelete
    Replies
    1. I seem to have this same issue. I have read the code from so many other forums and they all seem to have a similar approach. I am unable to save the grabbed image into an IplImage though.

      Delete
    2. If you get the error "Frame cannot be converted to IplImage " use the OpenCVFrameConverter as shown in this code:

      https://github.com/bytedeco/javacv#sample-usage

      Delete
  8. java.lang.NoClassDefFoundError: com/googlecode/javacpp/Pointer
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: com.googlecode.javacpp.Pointer
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" C:\Users\Aviral\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
    BUILD FAILED (total time: 0 seconds)

    m getting this error

    ReplyDelete
  9. my program is working correctly except when i open webcam I'm unable to see myself it all blank white but yet still it capturing the image

    ReplyDelete