1

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.

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.

  • 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. – Mukesh Aug 23 '18 at 23:02
  • 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. – Bernard Wei Aug 23 '18 at 23:11
  • I am using Ubuntu 18.04. Maybe that's the reason then. – Mukesh Aug 23 '18 at 23:12
  • 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. – Bernard Wei Aug 23 '18 at 23:13
  • sudo rm /dev/video0 ? Is this the code to remove the static node ? – Mukesh Aug 23 '18 at 23:15
1

/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.

  • 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. – Mukesh Aug 23 '18 at 23:01

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.