0

Good morning, I am working with Teststand 2021, I have been working with labview, c#, python all without problem, I was trying with a simple code to take a picture with a webcam using Python and I want to add this program to my sequence in teststand, I choose the script, I select the version of Python 3. 6 and when I load the program in teststand, Teststand runs it automatically indefinitely, the only way to stop it is to switch me from the "P Module" section to any other Teststand configuration section.

Next I leave the phyton code that takes the picture, the code works perfectly in Visual studio, the problem happens with Teststand when loading the python script, I leave you with the phyton code and an image of 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()

Testand: As you can see in the image the phyton script is executed when loading the module in Teststand, BUT I have not clicked on execute the sequence, Teststand should only execute the sequence or any of its steps until I select the start button at the top (green start button) so it seems crazy or an absurd bug that has never happened to me nor have I found information in the documentation of pyhton or teststand:

enter image description here

enter image description here

ti7
  • 16,375
  • 6
  • 40
  • 68
Ivan97
  • 1

0 Answers0