Webcam cannot be initialized properly.

Hello guys,
I would like to use a machine vision camera (usb3.0 cable) to connect the raspberry 4B for a machine vision projects with simulink, the machine vision camera has its own SDK, which has been done in the raspberry pi. Then, I used the v4l2loopback to create a virtual webcam into the point-/dev/video0. After all, I tested it use the command- "r=raspi; w=webcam(r)" to test the connection between the machine vision camera on raspberry pi and matlab, but I got an error at below:
r=raspi
r =
raspi with properties:
DeviceAddress: '192.168.137.208'
Port: 18734
BoardName: 'Raspberry Pi 2 Model B'
AvailableLEDs: {'led0'}
AvailableDigitalPins: [4,5,6,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]
AvailableSPIChannels: {'CE0','CE1'}
AvailableI2CBuses: {'i2c-1'}
AvailableWebcams: {'HT VirtualCam (platform:v4l2loopback-000)'}
I2CBusSpeed: 100000
AvailableCANInterfaces: {}
Supported peripherals
>> w=webcam(r)
Webcam cannot be initialized properly. Please check if the device HT VirtualCam (platform:v4l2loopback-000) is available and free to use.
Could someone can help me about how to make a non-stardard USB camera to be detected by matlab?
Thank you very much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 采纳的回答

Hi @chen,
From the error it seems like the camera is being used in some process and hence it was not able to create a connection in MATLAB.
To check if any of the process is using the webcam (outside the MATLAB), please follow the below steps.
  • Please check if any application is using the webcam by using "$ top" command in the pi terminal window.
  • Please check if any of the cron scheduler is using the webcam, by executing "$ crontab -e" and see if there are custom shell scripts or an application is running in timely basis.
  • If none of the above steps doesnot work we can reboot the Rasberry Pi using "$ sudo reboot" and confirm "$ fswebcam" works in the pi terminal and then go to MATLAB to create the webcam object.
  • If rebooting doesnot help, please follow the hardware setup process in MATLAB-> Addons-> Manage Addons->click on gear icon in Raspberry Pi support package and follow the setup process.
I hope this will resolve the issue! If you encounter any further problems, please feel free to reach out.

3 个评论

Thank you very much for your constructive suggestions! I have tried all the advices, and here is the output:
$ top -->
  • pi@raspberrypi-CQYE9wXeiU:~ $ top
  • top - 13:26:53 up 1:42, 2 users, load average: 0.25, 0.32, 0.25
  • Tasks: 172 total, 1 running, 171 sleeping, 0 stopped, 0 zombie
  • %Cpu(s): 0.5 us, 0.4 sy, 0.0 ni, 99.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
  • MiB Mem : 7847.2 total, 7101.9 free, 176.5 used, 568.8 buff/cache
  • MiB Swap: 100.0 total, 100.0 free, 0.0 used. 7431.1 avail Mem
  • PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  • 657 root 20 0 37216 19440 11228 S 1.3 0.2 1:23.20 vncserver-x11-c
  • 2581 pi 20 0 10412 3132 2600 R 1.3 0.0 0:00.18 top
  • 678 root 20 0 200340 48232 28320 S 0.7 0.6 1:10.89 Xorg
  • 690 root 20 0 13264 6236 5756 S 0.3 0.1 0:19.05 vncagent
  • 1875 pi 20 0 88376 28628 23672 S 0.3 0.4 0:02.36 lxterminal
  • 2579 root 20 0 0 0 0 I 0.3 0.0 0:00.05 kworker/u8:2-brcmf_wq/mmc1:0001:1
  • 1 root 20 0 33696 7888 6252 S 0.0 0.1 0:05.51 systemd
  • 2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd
  • 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
  • 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
  • 8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
  • 9 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks_rude_
  • 10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_tasks_trace
  • 11 root 20 0 0 0 0 S 0.0 0.0 0:00.41 ksoftirqd/0
  • 12 root 20 0 0 0 0 I 0.0 0.0 0:00.85 rcu_sched
  • 13 root rt 0 0 0 0 S 0.0 0.0 0:00.01 migration/0
  • 14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cpuhp/0
pi@raspberrypi-CQYE9wXeiU:~ $ crontab -e
  • no crontab for pi - using an empty one
  • Select an editor. To change later, run 'select-editor'.
  • 1. /bin/nano <---- easiest
  • 2. /usr/bin/vim.tiny
  • 3. /bin/ed
  • Choose 1-3 [1]: 1
  • No modification made
pi@raspberrypi-CQYE9wXeiU:~ $ fswebcam
  • --- Opening /dev/video0...
  • Trying source module v4l2...
  • /dev/video0 opened.
  • No input was specified, using the first.
  • Adjusting resolution from 384x288 to 640x480.
  • --- Capturing frame...
  • Captured frame in 0.00 seconds.
  • --- Processing captured image...
  • There are unsaved changes to the image.
And I have tried to reconnect the raspberry pi, the error is still there.
In addition, this camera is not based on a UVC driver, the engineers of this camera built a SDK, and I need run a scipt, which is call the camera send the photo to the point /dev/video0.
Thank you very much for your generous help!!!!!!!!!!!!!!!!!
Did you try following the last step
  • If rebooting doesnot help, please follow the hardware setup process in MATLAB-> Addons-> Manage Addons->click on gear icon in Raspberry Pi support package and follow the setup process.
Did this not work?
Also, try reinstalling the image on Raspberry Pi by choosing "Setup hardware with MathWorks Raspbian image" after executing following command in MATLAB.
w = matlab.hwmgr.internal.hwsetup.register.RaspberryPiWorkflow;
w.launch
Hi, @Gayathri. I use the matlab customized iamge for raspberry 4B(matlab-2021b), and I have tried the last step, but it did not work. But I have tried a standrad UVC camera of logitech, it works fine. Thank you very much!

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Raspberry Pi Hardware 的更多信息

产品

版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by