Camera is busy

Sorry if this is a really basic question but I’ve been trying to write our vision processing code using the raspberry pi as the camera server. My code is based on the example code in the RobotPy Docs (p.51) The code runs but the console logs:
bind() to port 1181 failed: Address already in use

ioctl VIDIOC_REQBUFS failed at UsbCameraImpl.cpp:513: Device or resource busy

USB Camera 0: could not allocate buffers

ioctl VIDIOC_S_FMT failed at UsbCameraImpl.cpp:777: Device or resource busy

USB Camera 0: could not set format 1 res 320x240

ioctl VIDIOC_S_PARM failed at UsbCameraImpl.cpp:798: Device or resource busy

USB Camera 0: could not set FPS to 30

ioctl VIDIOC_REQBUFS failed at UsbCameraImpl.cpp:513: Device or resource busy

USB Camera 0: could not allocate buffers

ioctl VIDIOC_S_FMT failed at UsbCameraImpl.cpp:777: Device or resource busy

USB Camera 0: could not set format 1 res 320x240

ioctl VIDIOC_S_PARM failed at UsbCameraImpl.cpp:798: Device or resource busy

USB Camera 0: could not set FPS to 30

ioctl VIDIOC_REQBUFS failed at UsbCameraImpl.cpp:513: Device or resource busy

USB Camera 0: could not allocate buffers

CS: USB Camera 0: Connecting to USB camera on /dev/video0

CS: ERROR: ioctl VIDIOC_S_FMT failed at UsbCameraImpl.cpp:777: Device or resource busy (UsbUtil.cpp:156)

CS: WARNING: USB Camera 0: could not set format 1 res 320x240 (UsbCameraImpl.cpp:779)

CS: ERROR: ioctl VIDIOC_S_PARM failed at UsbCameraImpl.cpp:798: Device or resource busy (UsbUtil.cpp:156)

CS: WARNING: USB Camera 0: could not set FPS to 30 (UsbCameraImpl.cpp:799)

CS: ERROR: ioctl VIDIOC_REQBUFS failed at UsbCameraImpl.cpp:513: Device or resource busy (UsbUtil.cpp:156)

CS: WARNING: USB Camera 0: could not allocate buffers (UsbCameraImpl.cpp:514)

Does anyone know why the device is busy? Is there some operation running in the background that’s already using the camera?

Usually it means that another application is using it. Assuming your are running Raspbian Lite, you can run htop to see what processes are running.

If you do not have htop installed you can install it by running ‘sudo apt-get install htop’.

Once you have found the program that is using the camera, remember its PID and then you can kill it by running ‘sudo kill -9 “the programs PID”’

If you are using the Raspbian desktop then you can kill the program using the task manager.

The very first line indicates that you already have a camera server running. Something started and opened network port 1181, and then your app is starting. So probably there is camera server that started automatically.

If you’re running this code on the FRCVision rPi image, there is a built-in default application running that connects to cameras and hosts a server on port 1181. If you want to temporarily disable the default application, click “Down” on the Vision Status tab of the web dashboard. If you want to keep it from running at startup, on the Application tab of the web dashboard, select Custom or one of the Uploaded options and click Save. Note that selecting the Uploaded Python file option gives you the opportunity to upload a python script that runs at startup.