0

I'm trying to use opencv to do some automatization but I need the camera's feed. The problem is now that everything works, i can't have an image that has a meaning...

I tried with a simple program using picamera to check if it was from my camera, it's not..

import cv2
import numpy as np

cap = cv2.VideoCapture(-1)

if (cap.isOpened() == False): 
  print("Unable to read camera feed")

frame_width = int(cap.get(3))
frame_height = int(cap.get(4))

while(True):
  ret, frame = cap.read()

  if ret == True: 
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
      break
  else:
    break 
cap.release()
cv2.destroyAllWindows() 

(taken from : learn opencv)

Like this is my room : screen of the output and I don't think it actually looks like that... Well, if you have an idea, feel free to help me, i'll be very gratefull. Cordially, Louis.

  • Are you using your system's camera or an external camera? If you are using external camera then you should change `cap = cv2.VideoCapture(0)` to `cap = cv2.VideoCapture(1)` – Rish Dec 24 '18 at 01:38
  • If i do "cap = cv2.VideoCapture(1)" the output is : "VIDEOIO ERROR: V4L: can't open camera by index 1" the only that works is "cap = cv2.VideoCapture(-1)" but it shows that strange image. – Louis MeMyself Dec 24 '18 at 02:04

1 Answers1

0

To work with picamera, I recommend you to use the package picamera. You can follow this tutorial to deploy picamera: https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/

Ha Bom
  • 2,787
  • 3
  • 15
  • 29
  • A last question, can i edit the output ? I want it to hightlight blank pixel and so by using this :"image[len(image)-1-i[0]][-2+j+i[1]]=[0,0,255]" but it gives me :"ValueError: assignment destination is read-only" – Louis MeMyself Dec 24 '18 at 02:05
  • This error occurs when you try to write to a read-only numpy array. According to https://stackoverflow.com/questions/13572448/replace-values-of-a-numpy-index-array-with-values-of-a-list, you can change it to write-able by `image.flags.writeable = True`. – Ha Bom Dec 24 '18 at 02:46