melexis / mlx90640-library

MLX90640 library functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MLX90640 raspberry pi connection using I2C interface Opencv

Exauce-belayi opened this issue · comments

Hello,

I would like to annotate over frames coming out of mlx90640 thermal camera using OpenCV. It is connected to the GPIO of the raspberry pi using I2C interface protocol. Seems like Opencv can recognize USB cams out of box but not i2c is it so? When I run my python code(with only import of cv2 ) to get annotated video output , I get an index error when using 1 or 0. This is maybe because in the code the object, source expects the camera to be connected serially through USB and not connected directly onto the raspberry pi module via i2c. Any thoughts on how to achieve this? If there is any code statements or component part that may be of use to solve this problem that will help a lot.
Here is the python code for this using opencv on raspberry pi:

import cv2

Use source = 0 to specify the web cam as the video source, OR

specify the pathname to a video file to read.

source = 1

Create a video capture object from the VideoCapture Class.

video_cap = cv2.VideoCapture(source)

Create a named window for the video display.

win_name = 'Video Preview'
cv2.namedWindow(win_name)

Enter a while loop to read and display the video frames one at a time.

while True:
# Read one frame at a time using the video capture object.
has_frame, frame = video_cap.read()
if not has_frame:
break
# Display the current frame in the named window.
cv2.imshow(win_name, frame)

# Use the waitKey() function to monitor the keyboard for user input.
# key = cv2.waitKey(0) will display the window indefinitely until any key i$
# key = cv2.waitKey(1) will display the window for 1 ms
key = cv2.waitKey(0)

# The return value of the waitKey() function indicates which key was presse$
# You can use this feature to check if the user selected the `q` key to qui$
if key == ord('Q') or key == ord('q') or key == 27:
    # Exit the loop.

video_cap.release()
cv2.destroyWindow(win_name)

Thanks.

This repo is all about implementation in the c-language. python is not addressed.
Have a look here if you want to use this lib in a python environment.
https://github.com/melexis-fir/mlx90640-driver-devicetree-py
Importing it into opencv is possible, but I didn't figure out how get the stream with only 'import cv2'
The example is a bit out of sync with the driver above, however it can inspire you on how to do it.
https://github.com/melexis-fir/mlx9064x-blob-detection-py/blob/master/examples/mlx90640_opencv_blob_detection.py#L171