Testand 中的错误,TestStand 在配置部分或自动无限循环中执行 Python 脚本

问题描述 投票:0回答:0

早上好,我正在使用 Teststand 2021,我一直在使用 Labview、C#、Python,一切都没有问题,我正在尝试使用简单的代码使用 Python 用网络摄像头拍照,我想将此程序添加到 Teststand 中的序列中,我选择脚本,选择 Python 3.6 的版本,当我在 Teststand 中加载程序时,Teststand 会无限期地自动运行它,停止它的唯一方法是将我从“P 模块”部分切换到任何其他测试台配置部分。

接下来我留下拍照的phyton代码,该代码在Visual studio中完美运行,加载python脚本时Teststand出现问题,我留下phyton代码和Teststand的图像。

Python:

import cv2
import numpy as np
import tkinter as tk

NOMBRE_FOTO = "Test.jpeg"
NUMERO_CAMARA = 0
cap = cv2.VideoCapture(NUMERO_CAMARA)
font = cv2.FONT_HERSHEY_SIMPLEX

def tomar_foto():
    try:
        leido, frame = cap.read()
    except:
        print("Error al acceder a la cámara")
        return False
    if leido == True:
        cv2.imwrite(NOMBRE_FOTO, frame)
        print("Foto tomada correctamente")
        return True
    else:
        print("No se pudo leer el frame de la cámara")
        return False

def mostrar_foto():
    foto_tomada = tomar_foto()
    if foto_tomada == True:
        frame = cv2.imread(NOMBRE_FOTO)
        edges = cv2.Canny(frame, 200, 300, True)  
        cv2.putText(frame, 'TEXTO GENERICO AQUI', (230,250), font, 1,(0,0,0),2)
        cv2.imshow("Test", frame)
        cv2.waitKey(0)
ventana = tk.Tk()
ventana.title("Tomar foto")
boton = tk.Button(ventana, text="Tomar foto", command=mostrar_foto)
boton.pack()
ventana.mainloop()
cap.release()
cv2.destroyAllWindows()

测试台: 正如您在图像中看到的那样,在 Teststand 中加载模块时会执行 phyton 脚本,但我没有单击执行序列,Teststand 应该只执行序列或其任何步骤,直到我选择顶部的启动按钮(绿色启动按钮),所以这看起来很疯狂或荒谬的错误,但我从未发生过,也没有在 pyhton 或 teststand 的文档中找到信息:

enter image description here

enter image description here

python unit-testing opencv labview teststand
© www.soinside.com 2019 - 2024. All rights reserved.