Jump to content

set spotmeter config

Recommended Posts


I am using thermal sensor and HAT Zero with Raaspberry Pi. I wanted to set ROI from my python script to get temperature. I have tried setting the ROI using ti.set_spotmeter_config(first_column=20, first_row = 20, last_column = 40, last_row = 40).  It is giving me this kind of error. 

    TypeError: set_spotmeter_config() takes 2 positional arguments but 5 were given

How can I resolve this error? 



#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Shows live thermal image video in Tk window

HOST = "localhost"
PORT = 4223
UID = "LcZ" # Change XYZ to the UID of your Thermal Imaging Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_thermal_imaging import BrickletThermalImaging

import math
import time
    from Tkinter import Tk, Canvas, PhotoImage, mainloop, Label # Python 2
    from Queue import Queue, Empty
    from tkinter import Tk, Canvas, PhotoImage, mainloop, Label # Python 3
    from queue import Queue, Empty

from PIL import Image, ImageTk

WIDTH  = 80
SCALE  = 10 # Use scale 5 for 400x300 window size (change for different size). Use scale -1 for maximized mode

image_queue = Queue()

# Creates standard thermal image color palette (blue=cold, red=hot)
def get_thermal_image_color_palette():
    palette = []

    for x in range(256):
        x /= 255.0
        palette.append(int(round(255*math.sqrt(x))))                  # RED
        palette.append(int(round(255*pow(x, 3))))                     # GREEN
        if math.sin(2 * math.pi * x) >= 0:
            palette.append(int(round(255*math.sin(2 * math.pi * x)))) # BLUE

    return palette

# Callback function for high contrast image
def cb_high_contrast_image(image):
    # Save image to queue (for loop below)
    global image_queue

def on_closing(window, exit_queue):

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    ti = BrickletThermalImaging(UID, ipcon) # Create device object
    ipcon.connect(HOST, PORT) # Connect to brickd
    print (ti.get_spotmeter_config())
    # Don't use device before ipcon is connected

    # Register illuminance callback to function cb_high_contrast_image
    ti.register_callback(ti.CALLBACK_HIGH_CONTRAST_IMAGE, cb_high_contrast_image)

    # Enable high contrast image transfer for callback
    # Create Tk window and label
    window = Tk()
    # Run maximized
    if SCALE == -1:        
        window.geometry("%dx%d+0+0" % (window.winfo_screenwidth(), window.winfo_screenheight()))
        window.update() # Update to resize the window
        w, h = window.winfo_width(), window.winfo_height()
        SCALE = min(w // WIDTH, h // HEIGHT)

    label = Label(window)

    image = Image.new('P', (WIDTH, HEIGHT))
    # This puts a color palette into place, if you 
    # remove this line you will get a greyscale image.
    exit_queue = Queue()
    window.protocol("WM_DELETE_WINDOW", lambda: on_closing(window, exit_queue))

    while True:        
            break # If the exit_queue is not empty, the window was closed.
        except Empty:
        # Get image from queue (blocks as long as no data available)
        image_data = image_queue.get(True)

        # Use original width/height to put data and resize again afterwards
        image = image.resize((WIDTH, HEIGHT))
        image = image.resize((WIDTH*SCALE, HEIGHT*SCALE), Image.ANTIALIAS)

        # Translate PIL Image to Tk PhotoImageShow and show as label
        photo_image = ImageTk.PhotoImage(image)
        y = ti.get_statistics()
        z = ((y[0][1]*655)/65535)- 273
        print (z)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...