Accidently deleted /dev/video0 and can't access the web cam via cheese

6,251

Solution 1

Try the recreating the video0 nod in the /dev directory to see if that solves your problem.

sudo mknod /dev/video0 c 81 0
sudo chown root:video /dev/video0
sudo chmod 660 /dev/video0

If you still having problem after this, try rebooting also.

Solution 2

/dev files are not-ordinary files, such as a .txt file, but they are interface to devices, like nodes, and most important they do not reside really on your (our) disk.

/dev files represent devices attached/on your computer, resident files are created run-rime.

The simplest solution to restore that file is to reboot your computer.
(when you power-off a computer, /dev is empty)

As an alternative, un-plug and plug the implicated device should have the same effect.

Share:
6,251

Related videos on Youtube

mozilla-firefox
Author by

mozilla-firefox

Asking and answering obvious questions on SO.

Updated on September 18, 2022

Comments

  • mozilla-firefox
    mozilla-firefox over 1 year

    To solve a issue I created another issue. I read this two code on some forum:

     sudo rm /dev/video0
     sudo mv /dev/video1 /dev/video0
    

    Now I can't access my web cam plus the python script that I had earlier written is giving problem viz:

    from cv2 import * 
    cam = cv2.VideoCapture(0) # some problem over here
    xx=1 //capture just one picture as soon as web cam gets opened
    while xx<2:
      ret, img = cam.read()
      cv2.imshow('img',img)
      value=random.randint(1,10000)
      cv2.imwrite("/home/mukesh/Desktop/recognition/recognition/unknown_pictures/filename"+str(value)+".jpg",img)
      xx+=1
      k = cv2.waitKey(30) & 0xff
      if k == 27:
        break
      cam.release()
      cv2.destroyAllWindows()
    

    Is there any way that I can recover back my dev/video0 file and get my web cam again. I completely messed up my laptop.

  • mozilla-firefox
    mozilla-firefox over 5 years
    Yes it worked by restarting but now in my code I had to tweak this cam = cv2.VideoCapture(0) as cam = cv2.VideoCapture(1). If it is left to 0 then an error is coming up VIDEOIO ERROR: V4L2. I am really clueless. Though it worked by changing 0 to 1 in the above code but I fail to understand the reason. Earlier it was working on 0 and not on 1 and now it's vice versa.
  • mozilla-firefox
    mozilla-firefox over 5 years
    Yes it worked after writing above 2 commands and then aftter restarting but now in my code I had to tweak this cam = cv2.VideoCapture(0) as cam = cv2.VideoCapture(1). If it is left to 0 then an error is coming up VIDEOIO ERROR: V4L2. I am really clueless. Though it worked by changing 0 to 1 in the above code but I fail to understand the reason. Earlier it was working on 0 and not on 1 and now it's vice versa.
  • Bernard Wei
    Bernard Wei over 5 years
    Which version of Ubuntu are you using? If you are using the later releases, 16.04 or later, it may be using udev exclusively. So it automatically create video1 when udev see the video0 static nod.
  • mozilla-firefox
    mozilla-firefox over 5 years
    I am using Ubuntu 18.04. Maybe that's the reason then.
  • Bernard Wei
    Bernard Wei over 5 years
    Okay, you can try this. Delete the static video0 we created and reboot. udev may recreate the 'video0' so your code can work with the device 0 again. You dev may be dynamic so no static nod is needed. I kinda remember it caches things so it may still like your video device to video1. But I may be wrong.
  • mozilla-firefox
    mozilla-firefox over 5 years
    sudo rm /dev/video0 ? Is this the code to remove the static node ?
  • Bernard Wei
    Bernard Wei over 5 years
    Yeah, try that and reboot. It may re-link it back to video0 or it may still link the device to video1. We'll see.
  • mozilla-firefox
    mozilla-firefox over 5 years
    It is working with 1 itself. Same error with 0. Actually I wanted to use IP webcam through mobile so that I can use that instead of normal webcam. Hence I tried to tweak webcam settings. My webcam is not much clear and hence image recognition is not tested properly on it.