окно imshow не может быть повторно использовано при вызове внутри потока в Raspberry Pi - PullRequest
0 голосов
/ 09 октября 2018
import numpy as np
import cv2
import os
import time
import datetime
from threading import Timer
from threading import Thread

def showVideo(capl, secs):
    time.sleep(secs)
    try:
        print("start video")
        while(capl.isOpened()):
            ret, frame = capl.read()
            cv2.namedWindow('frames', cv2.WND_PROP_FULLSCREEN)
            cv2.setWindowProperty('frames', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
            try:
                cv2.imshow('frames',frame)
                print("imshow")
            except:
                break

            if cv2.waitKey(50) & 0xFF == ord('q'):
                break

        capl.release()
        cv2.destroyAllWindows()
        print("End video")

    except Exception as e:
        print(e)

def bootProgramm():
    fileList = os.listdir('source/')
    getLength = len(fileList)
    i= 0
    print(fileList)
    while (i <= (getLength - 1)):
        print(fileList[i])
        #secs = 10
        #print(secs)

        x=datetime.datetime.now()
        y=x.replace(year=2018, month=10, day=9, hour=14, minute=(46+i), second=0, microsecond=0)
        delta_t = y - x
        secs = delta_t.seconds+1

        capl = cv2.VideoCapture('source/'+fileList[i])
        #showVideo(capl, secs)
        Thread(target = showVideo, args = (capl, secs)).start()    
        #Timer(secs, showVideo, [capl]).start()
        i=i+1


bootProgramm()

Это код.Показывается только 1-е видео, ошибок не было.Почему не работает малина?Эта же программа прекрасно работает в Windows, но не в малине.Кто-нибудь знает почему?Пожалуйста, помогите, я застрял в нем на много дней.Спасибо.

...