Advanced Iris Tracking Software
Re: Advanced Iris Tracking Software
Only one program can read the serial port at a time. But, once you have the script working in OpenMV IDE... Save the script to the camera, reset the camera, and then open the serial port in another application.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
I guess if you want a simpler answer, I simply want to take data off of the camera and onto visual studios.
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Sorry I didn't see your last post. So, I can write just a print statement and use the IDE terminal with the saved code and it will pickup on VS?
Re: Advanced Iris Tracking Software
Yes.
Note: On opening the VCP port make the DTR line active. The MicroPython OS will not print data unless this is active.
Note: On opening the VCP port make the DTR line active. The MicroPython OS will not print data unless this is active.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Excuse my beginner questions but how to I work the DTS and RTS? I have a RTS function in visual studios but I'm not sure how it works in Micropython.
Thanks
Thanks
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
After opening the serial port make sure to set the line. I can give you a snippet of Qt C++ code for example. This is one line of code normally.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
While I don't need the code for Qt, how do I write the code in micropython?
Re: Advanced Iris Tracking Software
Nothing has to be done on the cam for this. Just print data.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
So no settings, no code? Just save and reset?
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Hey if you could show me a bit of that Qt code, maybe that might help my issues. A while ago, I sent you a post with the current settings/variables in my VS code. If those could clear anything up, let me know.
Thanks.
Thanks.
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
If you understand C#, let me know and I could send you a bit of my code.
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Here you go:
Code: Select all
using System;
using System.IO.Ports;
using System.ComponentModel;
namespace EyeStuff
{
class PortDataReceived
{
public static void Main()
{
SerialPort mySerialPort = new SerialPort("COM3");
mySerialPort.BaudRate = 115200;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.RtsEnable = true;
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
mySerialPort.Open();
Console.WriteLine("Press any key to continue...");
Console.WriteLine();
Console.ReadKey();
mySerialPort.Close();
}
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.WriteLine("Data Received:");
Console.Write(indata);
}
}
}
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
The code compiles with no errors and it runs it's "Press any key" part, but it never prints out any data. At this point, I really don't know what the problem could be besides that I forgot something. Please let me know if you have any suggestions.
Thanks
Thanks
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Never mind I got it working. However, I wanted to say thank you for your help with the DTR. I forgot one line of code within my script and when I fixed it, everything worked fine. Thanks again.
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Hey I'm back again.
I just wanted to know, if I were to use serial pins to communicate between the two cameras, I would ONLY use pins 4 and 5, right? This is also the simplest way to communicate between the two correct?
Thanks.
I just wanted to know, if I were to use serial pins to communicate between the two cameras, I would ONLY use pins 4 and 5, right? This is also the simplest way to communicate between the two correct?
Thanks.
Re: Advanced Iris Tracking Software
Yes, communication is just a serial port between the two devices then. It's full duplex. You can use the struct module to send binary messages and decode them. Or, you can send data as text.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
So I can just use the print function to send text, and then create a statemachine on the other end to receive it?
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
I guess the better way to phrase it would be, what's the easiest way to receive data sent by the print command.
Re: Advanced Iris Tracking Software
No, use this:
import time
from pyb import UART
# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 19200, timeout_char = 1000)
while(True):
uart.write("Hello World!\r")
time.sleep(1000)
uart.write() accepts any formatted string. So, you can use python string formatting there. See all the uart methods: http://docs.openmv.io/library/pyb.UART. ... light=uart
import time
from pyb import UART
# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 19200, timeout_char = 1000)
while(True):
uart.write("Hello World!\r")
time.sleep(1000)
uart.write() accepts any formatted string. So, you can use python string formatting there. See all the uart methods: http://docs.openmv.io/library/pyb.UART. ... light=uart
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Awesome! So if that sends strings, how to I receive the strings? Also, don't need to declare the pins anywhere, correct?
Re: Advanced Iris Tracking Software
UART(3) is fixed to the same I/O pins.
As for receiving data. Please read the UART methods. In general, you want to call any() to see how many bytes are available and then read() that many bytes. If you'd like to see a great example... please see the Pixy Emulation UART script.
As for receiving data. Please read the UART methods. In general, you want to call any() to see how many bytes are available and then read() that many bytes. If you'd like to see a great example... please see the Pixy Emulation UART script.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
OK so I understand the code, but can I give you an example of how my physical pin system is set up? My system has two openMV cams both plugged into the computer via micro-USB cords. The two cams are then connected with two wires vis pins 4 and 5. Lastly, the camera that sends eye data is disconnected from the openMv IDE while the other is connected. Does this all sound about right?
Thanks again.
Thanks again.
Re: Advanced Iris Tracking Software
Yes, make sure both cameras share grounds and that RX plugs into TX of the other camera and TX plugs into RX of the other camera.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Thank you, now I have this code as a start but I know its wrong. Could you tell/show me what else I need to add to it.
Code: Select all
uart = UART(3, 19200, timeout_char = 1000)
while(True):
inData = uart.any()
print(inData);
time.sleep(1000)
Re: Advanced Iris Tracking Software
Code: Select all
uart = UART(3, 19200, timeout_char = 1000)
while(True):
count = uart.any()
if count:
print(uart.read(count))
time.sleep(1000)
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Thank you. So, I have everything all connected via pins 4 and 5, and my system has two connecting ground pins. Then I have one of the cameras plugged into the IDE while the other is disconnected. However, I still am not reading any data on my receiving camera. Do you have any ideas of what could be wrong?
Thanks
Thanks
Re: Advanced Iris Tracking Software
The code only prints to the IDE. If you want to send data over the UART you have to call the usrt.write() method. Print sends data back to the PC over USB.
Nyamekye,
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
So I replace all the example code you gave me with usrt?
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
If you want I can send you examples of my sending code. The code that's receiving the data is the code that you provided for me.
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
So for my sending code I have,
Then for my receiving code I have
The pins are then setup as I described before.
Thanks
Code: Select all
uart = pyb.UART(3, 115200)
while (True):
clock.tick()
# Capture snapshot
img = sensor.snapshot()
# Find eyes !
# Note: Lower scale factor scales-down the image more and detects smaller objects.
# Higher threshold results in a higher detection rate, with more false positives.
eyes = img.find_features(eyes_cascade, threshold=0.5, scale=1.5)
# Find iris
for e in eyes:
iris = img.find_eye(e)
img.draw_rectangle(e)
img.draw_cross(iris[0], iris[1])
uart.write("!EYE x:%d, y:%d, w:%d, h:%d" % e)
uart.write("!IRIS x:%d, y:%d" % iris)
Code: Select all
uart = UART(3, 19200, timeout_char = 1000)
#LED
blue_led = LED(3)
while(True):
count = uart.any()
if count:
print(uart.read(count))
blue_led.on()
time.sleep(1000)
Thanks
-
- Posts: 52
- Joined: Fri Mar 16, 2018 12:15 pm
Re: Advanced Iris Tracking Software
Never mind I got it working. However, I was wondering if you could tell me how to pull a string out of a string. MY data is currently being transmitted in the format of
I want to have just the x and y data values at the end, and I am curious as how to go about it. Thank you.
Code: Select all
uart.write("!EYE x:%d, y:%d, w:%d, h:%d" % e)
uart.write("!IRIS x:%d, y:%d" % iris)
Re: Advanced Iris Tracking Software
Hi, that would be a general purpose python question. You should Google about how to do that in Python and there's likely a lot of examples.
Nyamekye,
Re: Advanced Iris Tracking Software
Are you using VSCode to debug OpenMV code?
Welcome to Longer Vision
http://www.longervision.ca
http://www.longervision.ca
Return to “Project Discussion”
Who is online
Users browsing this forum: No registered users and 1 guest