They write a bot for telegrams, I wrote the function of sending a photo from a webcam, everything works, and there is one thing, the photo comes completely black, the light comes on the webcam, the photo comes, but completely black. What is the problem? Here is the code

from SimpleCV import Image, Camera elif command == '/snap': bot.sendChatAction(chat_id, 'typing') cam = Camera() img = cam.getImage() img.save('snap.jpg') bot.sendChatAction(chat_id, 'upload_photo') bot.sendDocument(chat_id, open('snap.jpg', 'rb')) os.remove('snap.jpg') 
  • 2
    1. First make sure that the camera itself is working. Can you get a normal image from it without a python (for example, in Skype or OS)? 2. Then try to run the script without the last line, then find the resulting snap.jpg file on the disk and see what is in it. Is the image in it completely black? If the answer to both questions is “yes”, then apparently there are some problems with the work of the SimpleCV library and you need to dig in this direction. - Xander
  • And here's what I found about your problem: stackoverflow.com/questions/17109245/… It looks like the camera, after instantiating the Camera () object, needs a little time before it is ready. Try to use the answers from that question. - Xander
  • @ Alexander, No, it did not help, now the photos are sent to the bot without stopping - Stranger
  • And what exactly did you do? Show new code. Which photos are sent without stopping - black or normal? - Xander
  • import Camera from SimpleCV import Camera cam = Camera () r = g = b = 0 while r + g + b <0.01: img = cam.getImage () r, g, b = img [img.width / 2, img. height / 2] print ("r: {} g: {} b: {}". format (r, g, b)) time.sleep (1) img.save (file_name) - Stranger

0