Advanced Iris Tracking Software

OpenMV related project discussion.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Tue Apr 17, 2018 1:38 pm

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,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Fri Apr 20, 2018 3:06 pm

I guess if you want a simpler answer, I simply want to take data off of the camera and onto visual studios.
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Fri Apr 20, 2018 3:07 pm

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?
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Fri Apr 20, 2018 7:33 pm

Yes.

Note: On opening the VCP port make the DTR line active. The MicroPython OS will not print data unless this is active.
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Mon Apr 23, 2018 10:47 am

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
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Mon Apr 23, 2018 11:16 am

*DTR
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Mon Apr 23, 2018 11:47 am

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,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Mon Apr 23, 2018 3:06 pm

While I don't need the code for Qt, how do I write the code in micropython?
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Mon Apr 23, 2018 3:52 pm

Nothing has to be done on the cam for this. Just print data.
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Mon Apr 23, 2018 4:34 pm

So no settings, no code? Just save and reset?
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Tue Apr 24, 2018 1:08 am

Hey man, you may wish to try by doing o_o.
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Tue Apr 24, 2018 10:38 am

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.
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Tue Apr 24, 2018 11:09 am

If you understand C#, let me know and I could send you a bit of my code.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Wed Apr 25, 2018 2:03 am

Paste it. Use the code tags.
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Wed Apr 25, 2018 10:33 am

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);
        }
    }
}
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Thu Apr 26, 2018 3:07 am

Okay, is it working?
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Thu Apr 26, 2018 10:30 am

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
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Thu Apr 26, 2018 6:04 pm

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.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Fri Apr 27, 2018 1:58 am

Great to hear!
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Thu May 03, 2018 11:24 am

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.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Fri May 04, 2018 12:31 am

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,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Fri May 04, 2018 10:39 am

So I can just use the print function to send text, and then create a statemachine on the other end to receive it?
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Fri May 04, 2018 10:44 am

I guess the better way to phrase it would be, what's the easiest way to receive data sent by the print command.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Fri May 04, 2018 11:14 am

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
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Fri May 04, 2018 11:26 am

Awesome! So if that sends strings, how to I receive the strings? Also, don't need to declare the pins anywhere, correct?
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Sat May 05, 2018 2:34 pm

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.
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Mon May 07, 2018 10:48 am

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.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Mon May 07, 2018 11:11 pm

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,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Tue May 08, 2018 10:42 am

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)
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Wed May 09, 2018 1:08 am

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,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Wed May 09, 2018 10:54 am

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
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Wed May 09, 2018 11:55 am

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,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Wed May 09, 2018 12:46 pm

So I replace all the example code you gave me with usrt?
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Wed May 09, 2018 1:43 pm

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.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Wed May 09, 2018 10:21 pm

Okay, I'll take a look.
Nyamekye,
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Thu May 10, 2018 10:37 am

So for my sending code I have,

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)
Then for my receiving code I have

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)
The pins are then setup as I described before.

Thanks
s-bbrackett
Posts: 52
Joined: Fri Mar 16, 2018 12:15 pm

Re: Advanced Iris Tracking Software

Postby s-bbrackett » Thu May 10, 2018 4:32 pm

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

Code: Select all

uart.write("!EYE x:%d, y:%d, w:%d, h:%d" % e)
        uart.write("!IRIS x:%d, y:%d" % iris)
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.
User avatar
kwagyeman
Posts: 2286
Joined: Sun May 24, 2015 2:10 pm

Re: Advanced Iris Tracking Software

Postby kwagyeman » Thu May 10, 2018 4:52 pm

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,
User avatar
jiapei100
Posts: 33
Joined: Fri Oct 14, 2016 7:07 pm
Contact:

Re: Advanced Iris Tracking Software

Postby jiapei100 » Wed Sep 12, 2018 1:27 pm

Are you using VSCode to debug OpenMV code?
Welcome to Longer Vision
http://www.longervision.ca

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest