Script autostart

Discussion related to "under the hood" OpenMV topics.
DCON81
Posts: 9
Joined: Wed Nov 01, 2017 4:14 pm

Script autostart

Postby DCON81 » Sun Mar 25, 2018 6:41 am

I've no sd card.
I want the script to start when board powered.
In the IDE i've done "Save open script to OPENMV Cam" but no autostart ...

I'm missing something ?
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Sun Mar 25, 2018 1:54 pm

Hi, after saving the script to the OpenMV Cam please click the reset OpenMV Cam button right under the save script button. The script should be flushed to the camera then and it should auto-start.
Nyamekye,
DCON81
Posts: 9
Joined: Wed Nov 01, 2017 4:14 pm

Re: Script autostart

Postby DCON81 » Wed Mar 28, 2018 10:56 am

Issue was solved updating the IDE and updating the firmware of the cam.
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Thu Jun 28, 2018 5:15 am

Hello! I connected OpenMV M7 to my Raspberry Pi... I want to open OpenMV IDE using python scripts, CONNECT to the camera, and START running the script... Does anyone know how to do it? Thanks
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Thu Jun 28, 2018 12:00 pm

Hi, are you talking about scripting up OpenMV IDE? Um, so, if you launch OpenMV IDE via the command line. You can pass it a file path as it's first argument and it will open that file. Then, if you can emulate pressing ctrl+e and then ctrl+r it will run the script.

Alternatively, you can save a script on the camera permanently and then launch the IDE using command line options which will allow you to create terminal windows to show the debug output for demo purposes. I built this feature into the IDE for folks. Does this sound like what you want? The script needs to be on the camera before hand... but, otherwise, you can launch the IDE and have it display debug output (without the text editor appearing and other buttons) via the command line.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Fri Jun 29, 2018 1:36 am

Thank you for the prompt reply sir kwagyeman!

Well what I want to happen is to automatically run the python script for the camera, not necessarily open the OPENMV IDE... Thanks!
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Fri Jun 29, 2018 1:55 am

1. Open the script in the IDE.
2. Go to Tools -> Save Script to OpenMV Cam
3. Go to Tools -> Reset OpenMV Cam

The script will now start when the camera starts.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Fri Jun 29, 2018 2:32 am

Thank you again for the prompt reply.... That information is very useful sir, however my code is still a work in progress... If "Save Open Script to OpenMV Cam" now and do it again with newly updated code, which code will it run when I boot it up?

Will it follow the most recent one? Thanks!
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Fri Jun 29, 2018 2:36 am

Yes. All this does is create/update a file called main.py on the OpenMV Cam. All micropython boards run a main.py script on startup.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Fri Jun 29, 2018 2:43 am

Hello! Last questions... I tried it out and it did run the autostart... However:

1. Is there a way that I may be able to see the images it sees?

2. I cant seem to stop the autostarted script since it boots up. How do I stop it without turning it off?

Thanks
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Fri Jun 29, 2018 2:47 am

Yes,

Go to Tools:

Open Terminal -> New Terminal -> Serial Port -> Select the right comm port -> Any baud rate (default is fine).

This pops open a terminal which will show you the

Code: Select all

print()
output from the camera. If you want to also see what the camera sees in this view you need to add

Code: Select all

print(img.compressed_for_ide(quality=50), end='')
to your script near the end of your while loop to tell the camera to send serial data over the USB port.

If you connect to the OpenMV Cam using the normal connect button the auto started script stops. If you'd like to permanently stop the auto start behavior delete the main.py file on your OpenMV Cam.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Fri Jun 29, 2018 3:01 am

Ok! Thank you sir!
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Fri Jul 06, 2018 3:55 am

Hello! I'm sorry for the additional questions... I'm currently attaching my OPENMV cam to my laptop and I'm running a GUI on python as can be seen on the attached image.

In the attached image, you can see the GUI. When the users clicks "enable camera", I would like the openmv to start its facial recognition script without having to open the OPENMV IDE and connecting to it.

Is there a way to run the scripts of the code by triggering it in a python script (GUI)? Thanks
Attachments
attach.png
attach.png (9.43 KiB) Viewed 160 times
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Fri Jul 06, 2018 1:12 pm

Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Mon Jul 09, 2018 2:35 am

Hello! Sorry I'm kinda having a hard time trying to understand that code... Do you mind helping me out a bit on how to set it up?

Let's say I connected my cam to my linux laptop in this port: "ttyACM0"

and have to run the script in this script: "home/pythonfiles/GUI/GUI_tester.py"

any help would be appreciated. Thanks!
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Mon Jul 09, 2018 1:33 pm

Ah, so, the script uses the /dev/openmvcam port which is created only if you install the openmv udev rules. In the top level of the OpenMV repo you need to install the udev rules. Once you do that then on Linux the camera will appear as a /dev/openmvcam device.

Please let me know if this works for you. Then, you can just run that script I linked to and provide it with a path to the script you want the camera to run.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Tue Jul 10, 2018 12:47 am

How do I do that exactly? I'm sorry I'm still new at this... I cloned the openmv repository... but I don't know how to install udev.
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Tue Jul 10, 2018 1:10 am

Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Tue Jul 10, 2018 3:50 am

Yes I did that and donwloaded it for RPi however I only have these files in the openmv/openmvide directory (see image attached)... there's no udev folder...
Attachments
OPEN.png
OPEN.png (112.6 KiB) Viewed 129 times
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Wed Jul 11, 2018 1:52 am

Go to share/qtcreaotr/pydfu.

However, if you just run the ./setup.sh script it takes care of the install for you.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Wed Jul 11, 2018 3:40 am

I did that before.. I tried it again but still no udev folder

I did:

cd openmv/openmvide

./setup.sh

on the terminal.. I also tried double clicking it an executing it, but nothing changed
Attachments
POST.png
POST.png (347.31 KiB) Viewed 111 times
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Wed Jul 11, 2018 12:07 pm

A udev folder will not appear. However, if you do "ls /dev" you should now see a device called "/dev/openmvcam".
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Thu Jul 12, 2018 1:36 pm

Hello! THank you! I will try that later. In the meantime, is there a way to send each frame the camera takes in real time to display in this GUI in Raspberry Pi?

maybe using the USB_VCP.send() function to send to the RPi through the usb port and the image.compress() function? Any help would be appreciated. Thank you!
Attachments
Untitled.png
Untitled.png (18.67 KiB) Viewed 90 times
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Thu Jul 12, 2018 3:35 pm

Yes, just do:

Code: Select all

print(img.compress(quality=90),end="")
You'll get a JPG byte stream. You may wish to send the size of the jpg byte stream first however.

Code: Select all

img.compress(quality=90)
print(str(img.size()) + \n)
print(img,end="")
You'd then scanf to get the size in bytes and then read that many bytes next.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Fri Jul 13, 2018 12:26 pm

Thank you! I see the dev/openmvcam did appear on my /dev.. I'm sorry for the additional questions, but I'm attaching my openmv to a gimbal and it doesnt really fit unless it is attached horizontally which means the view of the camera would be rotated about 90 degrees... I found the image.rotation_corr(z_rotation=90) but unfortunately, the rotated image was cropped because of the rotation... I'm currently using a 240x160 frame size if that's helpful... I also tried zooming to get rid of the black margins of the new rotated image (caused by the rotation), but it gets too zoomed

Is there a way to configure the sensor or change the image so that it is rotated 90 degrees without affecting the dimensions of the image or getting the image cropped. Thanks again for the help!
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Sat Jul 14, 2018 3:07 pm

As of right now there is not. However, if you set the resolution to something like QVGA and then set_windowing to a square res and then rotate that and then use an ROI of 240x160 you should get the results you want on the image.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Sat Jul 14, 2018 3:16 pm

yes... i thought of using a square dimensions too so that rotating it wouldn't be a problem... but I saw in the comments of the facial detection examples code that the 240x160 was the best for facial recognition... What can you suggest to be the best square dimensions for facial recognition... Thanks!
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Sat Jul 14, 2018 5:45 pm

Hi, that was the case of the M4. Not anymore. Um, just make sure the res is some form of 3:2.
Nyamekye,
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Sat Jul 14, 2018 5:47 pm

So, the method takes an ROI. Make the ROI a 3:2 area (240x160).
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Sun Jul 15, 2018 4:10 am

Hello! I'm sorry, I had no idea how to set the ROI to 240x120 after the image.snapshot() and image.rotation_corr() have been called... I couldn't find a method that set the windowing to 240x120... I tried image.copy() and printed it on the Open Terminal, but I didn't quite get the dimensions I needed... Thanks
Attachments
Untitled.png
Untitled.png (272.58 KiB) Viewed 57 times
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Sun Jul 15, 2018 1:13 pm

Find features takes an ROI: Pass roi=(0, 0, 240, 120) to find_features. Note that the ROI is in the upper left of the image. You'll want to adjust the x/y values to fix that if you want the ROI to start elsewhere.
Nyamekye,
levinpqr
Posts: 16
Joined: Thu Jun 28, 2018 5:09 am

Re: Script autostart

Postby levinpqr » Mon Jul 16, 2018 4:16 am

I tried it but unfortunately, I added the roi=[0,0,240,160] to the find_features() method, but the image is still cropped...
Attachments
Untitled.jpg
Untitled.jpg (296.88 KiB) Viewed 48 times
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: Script autostart

Postby kwagyeman » Mon Jul 16, 2018 1:44 pm

The ROI passed to find features is not displayed. It just tells the method where to work on in the image.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests