3
3
3Create2019-11-02 23:20:49
Python
3Create, 2019-11-02 23:20:49

Opencv and camera api?

Dear Opencv Experts. Help with a problem.
Xima camera. It has an API for Python.
I want to start doing something with streaming video from the camera... but still nothing...
Standard example for Opencv (can't run):
Tried to iterate over cv2.VideoCapture(0) - 0,1,2,3...
Crashes error:
cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame', gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

But the API example code works, it just opens a window from the camera and displays a streaming image.
How to adapt color change, search for contours to this api? At least hint.
from ximea import xiapi
import cv2

#create instance for first connected camera 
cam = xiapi.Camera()

#start communication
print('Opening first camera...')
cam.open_device()

#settings
cam.set_exposure(60000)

#create instance of Image to store image data and metadata
img = xiapi.Image()

#start data acquisition
print('Starting data acquisition...')
cam.start_acquisition()

try:

    while True:
        #get data and pass them from camera to img
        cam.get_image(img)

        #create numpy array with data from camera. Dimensions of the array are 
        #determined by imgdataformat
        data = img.get_image_data_numpy()

        print('data: ' + str(data))
        cv2.imshow('111', data)

        cv2.waitKey(1)
        
except KeyboardInterrupt:
    cv2.destroyAllWindows()

#stop data acquisition
print('Stopping acquisition...')
cam.stop_acquisition()

#stop communication
cam.close_device()

print('Done.')

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
3
3Create, 2019-11-03
@3Create

and no one can tell?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question