Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get temperature for x,y coordinate onmouse click OpenCV #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions examples/seekcamera-temp-opencv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env python3

from threading import Condition

import cv2

from seekcamera import (
SeekCameraIOType,
SeekCameraColorPalette,
SeekCameraManager,
SeekCameraManagerEvent,
SeekCameraFrameFormat,
SeekCamera,
SeekFrame, SeekCameraShutterMode, SeekCameraAGCMode, SeekCameraTemperatureUnit
)

class Renderer:
def __init__(self):
self.busy = False
self.frame = SeekFrame()
self.camera = SeekCamera()
self.frame_condition = Condition()
self.first_frame = True


def on_frame(_camera, camera_frame, renderer):
with renderer.frame_condition:
renderer.frame1 = camera_frame.thermography_float
renderer.frame = camera_frame.color_argb8888
renderer.frame_condition.notify()


def on_event(camera, event_type, event_status, renderer):
print("{}: {}".format(str(event_type), camera.chipid))

if event_type == SeekCameraManagerEvent.CONNECT:
if renderer.busy:
return
renderer.busy = True
renderer.camera = camera
renderer.first_frame = True
camera.color_palette = SeekCameraColorPalette.TYRIAN
camera.shutter_mode = SeekCameraShutterMode.MANUAL
camera.agMode = SeekCameraAGCMode.LINEAR
camera.tempunit = SeekCameraTemperatureUnit.CELSIUS
camera.register_frame_available_callback(on_frame, renderer)
camera.capture_session_start(SeekCameraFrameFormat.THERMOGRAPHY_FLOAT | SeekCameraFrameFormat.COLOR_ARGB8888)
# camera.capture_session_start(SeekCameraFrameFormat.COLOR_ARGB8888)

elif event_type == SeekCameraManagerEvent.DISCONNECT:
if renderer.camera == camera:
# Stop imaging and reset all the renderer state.
camera.capture_session_stop()
renderer.camera = None
renderer.frame = None
renderer.busy = False
elif event_type == SeekCameraManagerEvent.ERROR:
print("{}: {}".format(str(event_status), camera.chipid))
elif event_type == SeekCameraManagerEvent.READY_TO_PAIR:
return

def on_click(event, x, y, p1, temp_params):
temp,img = temp_params
if event == cv2.EVENT_LBUTTONDOWN:
print("Pixel Temperature is: ", temp[y, x]," °C. At coordinate: ",x, y)
cv2.circle(img, (x, y), 3, (0, 0, 0), -1)
cv2.imshow("Seek Thermal - Python OpenCV Sample", img)

def main():
window_name = "Seek Thermal - Python OpenCV Sample"
cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)

with SeekCameraManager(SeekCameraIOType.USB) as manager:
renderer = Renderer()
manager.register_event_callback(on_event, renderer)


while True:
with renderer.frame_condition:
if renderer.frame_condition.wait(150.0 / 1000.0):
img = renderer.frame.data
temp = renderer.frame1.data

if renderer.first_frame:
(height, width,_ ) = img.shape
cv2.resizeWindow(window_name, width * 2, height * 2)
renderer.first_frame = False

cv2.setMouseCallback(window_name, on_click,(temp,img))
cv2.imshow(window_name, img)

key = cv2.waitKey(1)
if key == ord("q"):
break

if not cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE):
break

cv2.destroyWindow(window_name)


if __name__ == "__main__":
main()