Hello dear jakaskerl
Firstly, thank you so much for your efforts.
What I am trying to do is to do some calculations based on the spatial location of my detection. In the photo below, I tried to print and send the data from the function as you told me. after the first reading and calculation the program stops as you can see.
This is the code that I am using:
import numpy as np
from depthai_sdk import OakCamera, ArgsParser
import argparse
import depthai as dai
import serial
import time
if name == 'main':
Arduino_data = serial.Serial('COM3', 115200)
Arduino_data.reset_input_buffer()
dx= 27.35
dy= 123.0979
dz= 45.57
yT= 452
x0 = 0
y0 = 0
z0 = 0
Gamma=0
def GettingSpatial(packet):
while True:
for det in packet.detections:
spatials = det.img_detection.spatialCoordinates
xc= spatials.x
x0= xc + dx
zc= spatials.z
Alpha= np.arctan(yT/zc)
CosAlpha= np.cos(Alpha)
z0= dz + (zc \*CosAlpha)
Gamma=np.rad2deg(np.arctan(x0/z0))
if Arduino_data.in_waiting > 0:
data = str(Gamma)
print(data)
Arduino_data.write(data.encode("utf-8"))
line = Arduino_data.readline().decode('utf-8').rstrip()
print(line)
parser = argparse.ArgumentParser()
parser.add_argument("-conf", "--config", help="Trained YOLO json config path", default=r"C:\Users\user\Desktop\codes\320\best300.json", type=str)
args = ArgsParser.parseArgs(parser)
with OakCamera(args=args) as oak:
stereo = oak.create_stereo(fps=8)
color = oak.create_camera('color', fps=8)
nn = oak.create_nn(args['config'], color, nn_type='yolo', spatial=stereo)
oak.visualize(nn, fps=True, scale=2/3)
oak.callback(nn.out.passthrough, GettingSpatial)
oak.start(blocking=True)
Thanks,