You are not logged in.

#1 2011-04-29 12:38:34

der_harm
Member
Registered: 2011-04-12
Posts: 32

[SOLVED] matlab image capturing using webcam

Hello,
I have installed the latest Matlab R2011a and now I want to process images using my webcam. The Image Acquisition Toolbox is installed.
Here I have documented my installation process:
https://wiki.archlinux.org/index.php/Us … arm#Matlab

-------------------------------
>> imaqhwinfo

ans =

    InstalledAdaptors: {'dcam'  'linuxvideo'}
        MATLABVersion: '7.12 (R2011a)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.1 (R2011a)'

>> imaqhwinfo('linuxvideo')

ans =

       AdaptorDllName: '/usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so'
    AdaptorDllVersion: '4.1 (R2011a)'
          AdaptorName: 'linuxvideo'
            DeviceIDs: {[1]  [2]}
           DeviceInfo: [1x2 struct]

>> imaqhwinfo('linuxvideo',1)

ans =

          DefaultFormat: 'RGB3_320x240'
    DeviceFileSupported: 0
             DeviceName: 'Hercules Dualpix HD Microphone'
               DeviceID: 1
      ObjectConstructor: 'videoinput('linuxvideo', 1)'
       SupportedFormats: {1x20 cell}

>> vid = videoinput('linuxvideo', 1, 'RGB3_320x240');
>> preview(vid)
Warning: Unable to reset the crop area.  Perhaps the device is in use.
??? Error using ==> imaqdevice.preview at 181
Could not connect to the image acquisition device.  Device may be in use.

>>
--------------------------------

Does anyone have an idea? I do not have an application started which uses my webcam, a reboot didn't work neither.
The command

# lsof | grep video

gives no results, when matlab is not started.
After the first command in matlab

>> imaqhwinfo

# lsof | grep video

gives me

MATLAB    4487      harm  mem       REG        8,6    83464   1870179 /usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so
MATLAB    4487 4532 harm  mem       REG        8,6    83464   1870179 /usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so
MATLAB    4487 4533 harm  mem       REG        8,6    83464   1870179 /usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so
MATLAB    4487 4534 harm  mem       REG        8,6    83464   1870179 /usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so
.
.
.
MATLAB    4487 4678 harm  mem       REG        8,6    83464   1870179 /usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so

Further details:

ls -la /dev/video*
lrwxrwxrwx  1 root root      6 29. Apr 10:52 /dev/video -> video0
crw-rw----+ 1 root video 81, 0 29. Apr 10:52 /dev/video0


I hope anybody can help me...
Cheers
Harm

Last edited by der_harm (2011-05-04 07:05:15)

Offline

#2 2011-05-02 14:07:53

Dave Tarkowski
Member
Registered: 2011-05-02
Posts: 2

Re: [SOLVED] matlab image capturing using webcam

I'm not sure why you are seeing this message.  At this point, we query the device for its default crop parameters and then try to set the crop parameters to those defaults.  Normally the only way that this would fail is because the device is currently in use by another application, but that is clearly not the problem here.

I have two questions.  First, the output of imaqhwinfo indicates that two devices are present.  Do you have two cameras connected to the computer?  Second, the format that you are trying to use is 320x240, which appears to be smaller than what your camera is capable of.  What happens if you try to use a larger format?  You can get a list of the supported formats with the following commands (or use IMAQTOOL):

>> info = imaqhwinfo('linuxvideo', 1);
>> info.SupportedFormats'

Choose the largest format from the list and then try previewing:

>> vid = videoinput('linuxvideo', 1, 'RGB3_1280x1024'); % I'm just guessing what the largest format will be
>> preview(vid)

Let me know how that goes.

Offline

#3 2011-05-03 08:00:49

der_harm
Member
Registered: 2011-04-12
Posts: 32

Re: [SOLVED] matlab image capturing using webcam

Hi Dave,
thanks for your reply:)
What I did not mention the last time:
LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so /usr/local/MATLAB/R2011a/bin/matlab
This I do to start matlab, as this would be the output without preloading the module:

>> imaqhwinfo

ans =

    InstalledAdaptors: {'dcam'  'linuxvideo'}
        MATLABVersion: '7.12 (R2011a)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '4.1 (R2011a)'

>> imaqhwinfo('dcam')

ans =

       AdaptorDllName: '/usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwdcamimaq.so'
    AdaptorDllVersion: '4.1 (R2011a)'
          AdaptorName: 'dcam'
            DeviceIDs: {1x0 cell}
           DeviceInfo: [1x0 struct]

>> imaqhwinfo('linuxvideo')

ans =

       AdaptorDllName: '/usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so'
    AdaptorDllVersion: '4.1 (R2011a)'
          AdaptorName: 'linuxvideo'
            DeviceIDs: {1x0 cell}
           DeviceInfo: [1x0 struct]

>>


I do have one webcam connected only, not two. Anyway imaqtool shows me two cams with exactly the same resolutions:


>> info = imaqhwinfo('linuxvideo', 1);
>> info.SupportedFormats'

ans =

    'BGR3_1024x768'
    'BGR3_1280x1024'
    'BGR3_320x240'
    'BGR3_640x480'
    'BGR3_800x600'
    'RGB3_1024x768'
    'RGB3_1280x1024'
    'RGB3_320x240'
    'RGB3_640x480'
    'RGB3_800x600'
    'YU12_1024x768'
    'YU12_1280x1024'
    'YU12_320x240'
    'YU12_640x480'
    'YU12_800x600'
    'YV12_1024x768'
    'YV12_1280x1024'
    'YV12_320x240'
    'YV12_640x480'
    'YV12_800x600'

>>

>> info = imaqhwinfo('linuxvideo', 2);
>> info.SupportedFormats'

ans =

    'BGR3_1024x768'
    'BGR3_1280x1024'
    'BGR3_320x240'
    'BGR3_640x480'
    'BGR3_800x600'
    'RGB3_1024x768'
    'RGB3_1280x1024'
    'RGB3_320x240'
    'RGB3_640x480'
    'RGB3_800x600'
    'YU12_1024x768'
    'YU12_1280x1024'
    'YU12_320x240'
    'YU12_640x480'
    'YU12_800x600'
    'YV12_1024x768'
    'YV12_1280x1024'
    'YV12_320x240'
    'YV12_640x480'
    'YV12_800x600'

>>


>> vid = videoinput('linuxvideo', 1, 'RGB3_1280x1024');
>> preview(vid)
Warning: Unable to reset the crop area.  Perhaps the device is in use.
??? Error using ==> imaqdevice.preview at 181
Could not connect to the image acquisition device.  Device may be in use.

>> vid = videoinput('linuxvideo', 1, 'RGB3_640x480');
>> preview(vid)
Warning: Unable to reset the crop area.  Perhaps the device is in use.
??? Error using ==> imaqdevice.preview at 181
Could not connect to the image acquisition device.  Device may be in use.

>>


For the dcam even preloading the module still does not work:

>> imaqhwinfo('dcam')

ans =

       AdaptorDllName: '/usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwdcamimaq.so'
    AdaptorDllVersion: '4.1 (R2011a)'
          AdaptorName: 'dcam'
            DeviceIDs: {1x0 cell}
           DeviceInfo: [1x0 struct]

>>


I have documented my installation process, is there anything wrong (see link in first post)??
Do you use matlab with linux? I have learned VIDEOINPUT is a new feature for UNIX systems...

Offline

#4 2011-05-03 08:26:45

der_harm
Member
Registered: 2011-04-12
Posts: 32

Re: [SOLVED] matlab image capturing using webcam

OK, what a shame... Once you know what to look for you find it immediately...
I just got a friends webcam and everything was just fine. My camera is not supported by the UVC driver, and so does not support Video 4 Linux 2 natively (?!?!?).
I have to buy a new camera:-p
http://www.mathworks.com/products/imaq/ … Linux.html


Thanks for helping:)!!!

---------------


My friends camera

#dmesg | tail
[12112.609033] usb 1-1: new high speed USB device using ehci_hcd and address 4
[12113.452499] uvcvideo: Found UVC 1.00 device USB Video Camera (0471:20ba)
[12113.454846] input: USB Video Camera as /devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0/input/input10
[12113.455055] usbcore: registered new interface driver uvcvideo
[12113.455059] USB Video Class driver (v1.0.0)

>> imaqhwinfo('linuxvideo')

ans =

       AdaptorDllName: '/usr/local/MATLAB/R2011a/toolbox/imaq/imaqadaptors/glnx86/mwlinuxvideoimaq.so'
    AdaptorDllVersion: '4.1 (R2011a)'
          AdaptorName: 'linuxvideo'
            DeviceIDs: {[1]  [2]}
           DeviceInfo: [1x2 struct]

>> info = imaqhwinfo('linuxvideo', 1);
>> info.SupportedFormats'

ans =

    'YUYV_320x240'
    'YUYV_640x480'

>> vid = videoinput('linuxvideo',1,'YUYV_640x480')

Summary of Video Input Object Using 'USB Video Camera'.

   Acquisition Source(s):  Camera 1 is available.

  Acquisition Parameters:  'Camera 1' is the current selected source.
                           10 frames per trigger using the selected source.
                           'YUYV_640x480' video data to be logged upon START.
                           Grabbing first of every 1 frame(s).
                           Log data to 'memory' on trigger.

      Trigger Parameters:  1 'immediate' trigger(s) on START.

                  Status:  Waiting for START.
                           0 frames acquired since starting.
                           0 frames available for GETDATA.

>> preview(vid)

>>
-------------------

My camera

#dmesg | tail
[12527.958808] usb 1-1: new high speed USB device using ehci_hcd and address 5
[12528.085053] gspca: probing 06f8:3003
[12528.202812] ov534_9: Sensor ID: 9657
[12528.371377] gspca: video0 created
[12528.373072] 5:2:1: cannot get freq at ep 0x84
[12528.502436] 5:2:1: cannot get freq at ep 0x84
[12528.506923] 5:2:1: cannot get freq at ep 0x84


>> vid = videoinput('linuxvideo',1,'RGB3_640x480')

Summary of Video Input Object Using 'Hercules Dualpix HD Microphone'.

   Acquisition Source(s):  ov534_9 is available.

  Acquisition Parameters:  'ov534_9' is the current selected source.
                           10 frames per trigger using the selected source.
                           'RGB3_640x480' video data to be logged upon START.
                           Grabbing first of every 1 frame(s).
                           Log data to 'memory' on trigger.

      Trigger Parameters:  1 'immediate' trigger(s) on START.

                  Status:  Waiting for START.
                           0 frames acquired since starting.
                           0 frames available for GETDATA.

>> preview(vid)
Warning: Unable to reset the crop area.  Perhaps the device is in use.
??? Error using ==> imaqdevice.preview at 181
Could not connect to the image acquisition device.  Device may be in use.

>>

Offline

#5 2011-05-03 12:53:18

Dave Tarkowski
Member
Registered: 2011-05-02
Posts: 2

Re: [SOLVED] matlab image capturing using webcam

I'm glad that you found the root of your problem.  It looks like I need to improve the detection of Video 4 Linux devices and handle them better, i.e. either support them fully or give a useful error message.

In the future, you'll probably get quicker answers to your MATLAB questions by posting either on MATLAB Answers or the MATLAB Newsgroup.

-Dave

Offline

#6 2011-05-03 16:37:40

der_harm
Member
Registered: 2011-04-12
Posts: 32

Re: [SOLVED] matlab image capturing using webcam

Hi Dave,
thanks for your advice.
And I just saw that you have joined this forum just yesterday to answer my question - wow thanks a lot...:)

Cheers
Harm

Last edited by der_harm (2011-05-03 16:38:02)

Offline

#7 2011-05-03 22:57:47

ngoonee
Forum Fellow
From: Between Thailand and Singapore
Registered: 2009-03-17
Posts: 7,259

Re: [SOLVED] matlab image capturing using webcam

Please mark the thread as [solved] (edit your first post).


Allan-Volunteer on the (topic being discussed) mailn lists. You never get the people who matters attention on the forums.
jasonwryan-Installing Arch is a measure of your literacy. Maintaining Arch is a measure of your diligence. Contributing to Arch is a measure of your competence.
Griemak-Bleeding edge, not bleeding flat. Edge denotes falls will occur from time to time. Bring your own parachute.

Offline

Board footer

Powered by FluxBB