Two Image show in PC with Used pyopenmv_multi

Discussion related to "under the hood" OpenMV topics.
skylin008
Posts: 65
Joined: Mon Mar 13, 2017 10:18 pm

Two Image show in PC with Used pyopenmv_multi

Postby skylin008 » Mon Nov 25, 2019 11:03 pm

Hello Eevery One! I want to show two Image from two Openmv4 snapshot(left side/right side) In same Windows with used pyopenmv_multi.py script.But as follow script as show Image2.How solve this issue:

Code: Select all

#!/usr/bin/env python2
# This file is part of the OpenMV project.
#
# Copyright (c) 2013-2019 Ibrahim Abdelkader <[email protected]>
# Copyright (c) 2013-2019 Kwabena W. Agyeman <[email protected]>
#
# This work is licensed under the MIT license, see the file LICENSE for details.
#
# An example script using pyopenmv to grab the framebuffer.

import sys
import numpy as np
import pygame
import pyopenmv_multi as pyopenmv
from time import sleep

select_Rect = pygame.Rect(0, 0, 0, 0)

# init pygame
pygame.init()

if len(sys.argv)!= 5:
    print ('usage: pyopenmv_multi.py <serial1 port> <script1> <serial2 port> <script2>')
    sys.exit(1)

with open(sys.argv[2], 'r') as fin1:
    buf1 = fin1.read()

with open(sys.argv[4], 'r') as fin2:
	buf2 = fin2.read()

portname1 = sys.argv[1]
portname2 = sys.argv[3]
connected1 = False
connected2 = False
pyopenmv.disconnect(portname1)
pyopenmv.disconnect(portname2)
for i in range(10):
    try:
        # opens CDC port.
        # Set small timeout when connecting
        pyopenmv.init(portname1, baudrate=921600, timeout=0.3)
        pyopenmv.init(portname2, baudrate=921600, timeout= 0.3)
        #pyopenmv.init(portname)
        connected1 = True
        connected2 = True
        break
    except Exception as e:
        connected1 = False
        connected2 = False
        sleep(0.100)

if not connected1 and not connected2:
    print ( "Failed to connect to OpenMV's serial port.\n"
            "Please install OpenMV's udev rules first:\n"
            "sudo cp openmv/udev/50-openmv.rules /etc/udev/rules.d/\n"
            "sudo udevadm control --reload-rules\n\n")
    sys.exit(1)

# Set higher timeout after connecting for lengthy transfers.
pyopenmv.set_timeout(portname1, 1*2) # SD Cards can cause big hicups.
pyopenmv.set_timeout(portname2, 1*2)
pyopenmv.stop_script(portname1)
pyopenmv.stop_script(portname2)
pyopenmv.enable_fb(portname1, True)
pyopenmv.enable_fb(portname2, True)
pyopenmv.exec_script(portname1, buf1)
pyopenmv.exec_script(portname2, buf2)

# init screen
running = True
fullscreen = True

Clock = pygame.time.Clock()
font = pygame.font.SysFont("monospace", 15)

while running:
    Clock.tick(100)

    # read framebuffer
    fb1 = pyopenmv.fb_dump(portname1)
    fb2 = pyopenmv.fb_dump(portname2)

    if fb1 != None and fb2 != None:
        # create image from RGB888
        image1 = pygame.image.frombuffer(fb1[2].flat[0:], (fb1[0], fb1[1]), 'RGB')
        image2 = pygame.image.frombuffer(fb2[2].flat[0:], (fb2[0], fb2[1]), 'RGB')

        
        # TODO check if res changed
        screen1 = pygame.display.set_mode((fb1[0], fb1[1]), pygame.DOUBLEBUF, 32)
        screen2 = pygame.display.set_mode((fb2[0], fb2[1]), pygame.DOUBLEBUF, 32)
       

        fps = Clock.get_fps()
        # blit stuff
        screen1.blit(image1, (-50, -50))
        screen2.blit(image2, (50, 50))
        screen1.blit(font.render("FPS %.2f"%(fps), 1, (255, 0, 0)), (0, 0))       

        # update display
        pygame.display.flip()
        
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
             running = False
        
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                running = False
            if event.key == pygame.K_c:
                pygame.image.save(image1, "capture1.png")
                pygame.image.save(image2, "capture2.png")
            if event.type == pygame.VIDEORESIZE:
                size = event.size
                width, height = size
                screen = pygame.display.set_mode(size, RESIZABLE)



pygame.quit()
pyopenmv.stop_script(portname1)
pyopenmv.stop_script(portname2)
Thanks Advance!
User avatar
iabdalkader
Posts: 1190
Joined: Sun May 24, 2015 3:53 pm

Re: Two Image show in PC with Used pyopenmv_multi

Postby iabdalkader » Tue Nov 26, 2019 6:10 am

Draw the two images side by side ? Anyway, this is a pygame question I'm sure you'll find a lot of examples.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests