cv2.error: /home/pi/opencv-3.4.0/modules/core/incl

2019-08-20 17:59发布

问题:

I have 2 cameras (1 - Kayeton KYT-U200-R01 and 2 - similar one but for IR) running on my Raspberry Pi 3. Everything worked fine but suddenly after resolution has been changed from 640x480 to 1024x768 on both the second camera refused to work. The error I get switching over to the second camera is as follows:

cv2.error: /home/pi/opencv-3.4.0/modules/core/include/opencv2/core/mat.inl.hpp:500: error: (-215) total() == 0 || data != __null in function Mat

Even after restoring previous resolution and system reboot the second camera won't work. If someone came across this issue before, please write your solution, thanks in advance.

Here is my Python code:

Camera initialization

def init_cameras(self):
    self.cap_1 = cv2.VideoCapture(1)
    self.cap_1.set(cv2.CAP_PROP_FPS, 1)

    # set resolution
    self.cap_1.set(3, 640)
    self.cap_1.set(4, 480)

    self.cap_2 = cv2.VideoCapture(0)
    self.cap_2.set(cv2.CAP_PROP_FPS, 1)

    # set resolution
    self.cap_2.set(3, 640)
    self.cap_2.set(4, 480)

Frame reading

def get_img_frame_from_camera_two(self):
    ret, img_frame = self.cap_2.read()
    # to save it when 'capture' button will be clicked
    self.save_last_img(img_frame)

    qFormat = QtGui.QImage.Format_RGB888

    img_frame = QtGui.QImage(img_frame, img_frame.shape[1], img_frame.shape[0], img_frame.strides[0], qFormat)
    img_frame = img_frame.rgbSwapped()

    return img_frame

Run method of separate thread to read the frame

def run(self):
    while(True):
        while(self.event_running.isSet()):
            img_frame = self.camera_manager.get_img_frame_from_camera_two()
            frame = {}
            frame['img'] = img_frame
                if self.camera_manager.queue_frames_camera_two.qsize() < 10:
                    # put frame to queue
                    self.camera_manager.queue_frames_camera_two.put(frame)
                    # notify listener on new frame added in
                    self.camera_manager.signal_camera_two.emit()
                else:                        
                    print(self.camera_manager.queue_frames_camera_two.qsize())