Skip to content

Add 2 arguments to camtest.py #14

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

Merged
merged 5 commits into from
Apr 14, 2020
Merged
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
32 changes: 28 additions & 4 deletions examples/mlx90640_camtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import math
import time
import argparse
import board
import busio
from PIL import Image
Expand All @@ -22,11 +23,31 @@
# high range of the sensor (this will be white on the screen)
MAXTEMP = 50.0

# if in windowed mode, make the window bigger by this factor
WINDOW_SCALING_FACTOR = 50

# parse command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--windowed", action="store_true", help="display in a window")
parser.add_argument(
"--disable-interpolation",
action="store_true",
help="disable interpolation in-between camera pixels",
)

args = parser.parse_args()

# set up display
os.environ["SDL_FBDEV"] = "/dev/fb0"
os.environ["SDL_VIDEODRIVER"] = "fbcon"
if not args.windowed:
os.environ["SDL_FBDEV"] = "/dev/fb0"
os.environ["SDL_VIDEODRIVER"] = "fbcon"
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
if not args.windowed:
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
else:
screen = pygame.display.set_mode(
[32 * WINDOW_SCALING_FACTOR, 24 * WINDOW_SCALING_FACTOR]
)
print(pygame.display.Info())

# the list of colors we can choose from
Expand Down Expand Up @@ -117,10 +138,13 @@ def gradient(x, width, cmap, spread=1):
# pixelrgb = [colors[constrain(int(pixel), 0, COLORDEPTH-1)] for pixel in pixels]
img = Image.new("RGB", (32, 24))
img.putdata(pixels)
img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC)
if not args.disable_interpolation:
img = img.resize((32 * INTERPOLATE, 24 * INTERPOLATE), Image.BICUBIC)
img_surface = pygame.image.fromstring(img.tobytes(), img.size, img.mode)
pygame.transform.scale(img_surface.convert(), screen.get_size(), screen)
pygame.display.update()
if args.windowed:
pygame.event.pump()
print(
"Completed 2 frames in %0.2f s (%d FPS)"
% (time.monotonic() - stamp, 1.0 / (time.monotonic() - stamp))
Expand Down