Script autostart
Script autostart
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 ?
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 ?
Re: Script autostart
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,
Re: Script autostart
Issue was solved updating the IDE and updating the firmware of the cam.
Re: Script autostart
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
Re: Script autostart
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.
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,
Re: Script autostart
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!
Well what I want to happen is to automatically run the python script for the camera, not necessarily open the OPENMV IDE... Thanks!
Re: Script autostart
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.
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,
Re: Script autostart
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!
Will it follow the most recent one? Thanks!
Re: Script autostart
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,
Re: Script autostart
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
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
Re: Script autostart
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 output from the camera. If you want to also see what the camera sees in this view you need to add 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.
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()
Code: Select all
print(img.compressed_for_ide(quality=50), end='')
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,
Re: Script autostart
Ok! Thank you sir!
Re: Script autostart
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
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 (9.43 KiB) Viewed 13966 times
Re: Script autostart
Yes, use this script: https://github.com/openmv/openmv/blob/m ... yopenmv.py
Nyamekye,
Re: Script autostart
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!
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!
Re: Script autostart
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.
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,
Re: Script autostart
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.
Re: Script autostart
Nyamekye,
Re: Script autostart
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 (112.6 KiB) Viewed 13935 times
Re: Script autostart
Go to share/qtcreaotr/pydfu.
However, if you just run the ./setup.sh script it takes care of the install for you.
However, if you just run the ./setup.sh script it takes care of the install for you.
Nyamekye,
Re: Script autostart
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
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 (347.31 KiB) Viewed 13917 times
Re: Script autostart
A udev folder will not appear. However, if you do "ls /dev" you should now see a device called "/dev/openmvcam".
Nyamekye,
Re: Script autostart
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!
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 (18.67 KiB) Viewed 13896 times
Re: Script autostart
Yes, just do:
You'll get a JPG byte stream. You may wish to send the size of the jpg byte stream first however.
You'd then scanf to get the size in bytes and then read that many bytes next.
Code: Select all
print(img.compress(quality=90),end="")
Code: Select all
img.compress(quality=90)
print(str(img.size()) + \n)
print(img,end="")
Nyamekye,
Re: Script autostart
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!
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!
Re: Script autostart
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,
Re: Script autostart
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!
Re: Script autostart
Hi, that was the case of the M4. Not anymore. Um, just make sure the res is some form of 3:2.
Nyamekye,
Re: Script autostart
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 (272.58 KiB) Viewed 13863 times
Re: Script autostart
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,
Re: Script autostart
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 (296.88 KiB) Viewed 13854 times
Re: Script autostart
The ROI passed to find features is not displayed. It just tells the method where to work on in the image.
Nyamekye,
Re: Script autostart
Hello! I bought multiple of these openmv cameras, and I wanted to use them in different ways... Since I attached my openmv cam to a gimbal of a drone, it is extremely difficult for the gimbal to carry the camera with a usb connected to it (used for real-time image streaming)... so I wanted to ask if there is a way to send the image.snapshot() images over the UART port so that the camera would no longer be heavy?
Thanks
Thanks
Re: Script autostart
Hi, just do:
uart.write(img.compress())
On a valid uart object (see example scripts to make one). Or, alternatively, you can do img.compressed_for_ide() if you're sending the data back to the IDE. Note that the data rate is so high that USB is really the other thing that cuts it for sending video. WiFi may also.
Ibrahim is finally working on WiFi programming support.
uart.write(img.compress())
On a valid uart object (see example scripts to make one). Or, alternatively, you can do img.compressed_for_ide() if you're sending the data back to the IDE. Note that the data rate is so high that USB is really the other thing that cuts it for sending video. WiFi may also.
Ibrahim is finally working on WiFi programming support.
Nyamekye,
Re: Script autostart
Thanks! Will try that soon! Anyway, I'm trying to determine the distance of a human from the camera through the image it sees, and I've tried doing some experiments on determining the focal length of the camera, however my experiments were not that consistent... Any chance you guys know what the focal length of the camera is? I'm currently using the OpenMV M7 camera... Thanks
Re: Script autostart
Hello! I tried streaming the image through the USB VCP class and the byte size of the image through the UART class as seen on the first image... But when I try to read the amount of bytes in the usb connection (as seen in the 2nd image), it says the buffer is not large enough... I searched for the specs of the camera and got 300KB++ buffer size... as seen on the 2nd image, the byte size of each snapshot is around 2000+ bytes, so I'm not sure what's going on... I have a 16GB sd card attached to the openmv. Can you help me out? Thanks!
- Attachments
-
- POST.png (168.05 KiB) Viewed 13743 times
-
- post2.png (205.64 KiB) Viewed 13743 times
Re: Script autostart
Hi, the error is coming from your Pi. Not the camera. The code on the camera looks fine.
The issues is the frombuffer call. Please note that the image is in JPG format. So:
The issues is the frombuffer call. Please note that the image is in JPG format. So:
Code: Select all
import os
import io
import Image
from array import array
image = Image.open(io.BytesIO(image_data))
image.show()
Nyamekye,
Re: Script autostart
Hello! I tried doing what you suggested with the following revisions of the code... So the serial port delivers the length of the bytes of the image and the USBVCP delivers the image in bytes (as seen in the first picture)... The python script receiving this takes the bytes and stores it in the string... I tried to print these bytes in the openmv ide and got that the bytes were:
\xff\x00\ and further stuff like this
However these characters seem to be stored in a string instead of a byte object as seen on the 3rd picture... I tried adding the Image.open(io.BytesIO()) but it got me an error saying "cannot identify image file <_io.BytesIO object at 0x75784960>"
and I also tried replacing it with Image.open(io.StringIO()) but still nothing...
Sorry for the inconvenience.. Thanks!
\xff\x00\ and further stuff like this
However these characters seem to be stored in a string instead of a byte object as seen on the 3rd picture... I tried adding the Image.open(io.BytesIO()) but it got me an error saying "cannot identify image file <_io.BytesIO object at 0x75784960>"
and I also tried replacing it with Image.open(io.StringIO()) but still nothing...
Sorry for the inconvenience.. Thanks!
- Attachments
-
- POST.png (130.46 KiB) Viewed 13715 times
-
- POST 2.png (152.07 KiB) Viewed 13715 times
-
- POST 3.png (441.45 KiB) Viewed 13715 times
Re: Script autostart
Hi, I got the answer I posted from here:
https://stackoverflow.com/questions/329 ... -byte-file
Unfortunately, I can't really debug this for you more than to point you in the right place. As long as you received the right number of bytes on the Pi side you should have a valid image file that is a jpg.
From the debug output it looks like you received the image fine. So, jpg images always end with FFD9 and begin with FFD8. So, it looks like you received the full image.
Mmm, as a test try writing the binary byte object to disk and then open it.
The file should be in binary on disk... if you notice that the file grew in size from what you script printed out then that means you're silently converting the bytes from binary form to text strings of what the binary data is...
https://stackoverflow.com/questions/329 ... -byte-file
Unfortunately, I can't really debug this for you more than to point you in the right place. As long as you received the right number of bytes on the Pi side you should have a valid image file that is a jpg.
From the debug output it looks like you received the image fine. So, jpg images always end with FFD9 and begin with FFD8. So, it looks like you received the full image.
Mmm, as a test try writing the binary byte object to disk and then open it.
Code: Select all
file = open("image.jpg", "wb")
file.write(image_data[0])
file.close()
Nyamekye,
Re: Script autostart
Hello! Sorry for the late response, but I had it working already. Thanks for the many help!... The serial.read(# of bytes) didnt really read accurately so I just assigned a value bigger than the number of bytes of the image...
I was able to get the right data by searching for the start bytes: '\xff\xd8'
and end bytes: '\xff\xd9'
of the jpeg data...
Anyway... I tried just streaming the images from the openMV to the Raspberry Pi, and let the face detection be done by the Raspberry Pi through OpenCV, however its very slow in image processing (even though I used LBP cascade over haar).. I only get a maximum of 5 FPS from the face detection.. so I tried making the OpenMV do the face detection again... But the problem is that the face detection of the OpenMV (the one in the examples) seem to be unable to detect a face about 2m away...
I'm currently using the QVGA resolution and windowing of 240x240... Is there any way that the openmv be able to do a facial detection at least 2m away? Or maybe a different facial detection algorithm? Thanks
I was able to get the right data by searching for the start bytes: '\xff\xd8'
and end bytes: '\xff\xd9'
of the jpeg data...
Anyway... I tried just streaming the images from the openMV to the Raspberry Pi, and let the face detection be done by the Raspberry Pi through OpenCV, however its very slow in image processing (even though I used LBP cascade over haar).. I only get a maximum of 5 FPS from the face detection.. so I tried making the OpenMV do the face detection again... But the problem is that the face detection of the OpenMV (the one in the examples) seem to be unable to detect a face about 2m away...
I'm currently using the QVGA resolution and windowing of 240x240... Is there any way that the openmv be able to do a facial detection at least 2m away? Or maybe a different facial detection algorithm? Thanks
Re: Script autostart
Hi, by chaining the scale value you change how many scales the algorithm tries.
https://github.com/openmv/openmv/blob/m ... aar.c#L108
Basically, by making the value closer to 1.0 you make the algorithm scale more slowly down in size.
https://github.com/openmv/openmv/blob/m ... aar.c#L108
Basically, by making the value closer to 1.0 you make the algorithm scale more slowly down in size.
Nyamekye,
Re: Script autostart
Hello sir! Thank you for the help! However I encountered another problem. I have attached one of my cams to a gimbal as seen on the attachment... however my USB connection to the RPi gets cut off suddenly. Do u have any suggestions for this? Thanks
Re: Script autostart
Sorry for that previous reply.. Please disregard this... Is there a way I can run the python script of the OpenMVIDE using the pyopenmv.py through the serial connection?
I tried changing the /dev/openmvcam port of the pyopenmv.py to /dev/ttyS0 which is the serial port, but it didn't work. Thanks
I tried changing the /dev/openmvcam port of the pyopenmv.py to /dev/ttyS0 which is the serial port, but it didn't work. Thanks
Re: Script autostart
Hi, you have to install udev drivers for the /dev/openmvcam device to appear. That said, this isn't actually needed except if you want to use DFU. All you need to do is change the serial port to the /dev/ACM whatever port that appears when you connect the camera.
Nyamekye,
Re: Script autostart
Hello! Thank you for the many many help... I've accomplished a lot of projects and features with this camera!
I was wondering, by the way, is there any way I could import my own classifier xml file. Let's say I want to do Upper Body Detection using an upper body xml, how would I import that? I couldn't find a frontal xml file used for your facial detection, so I don't really know how the classifiers are imported into the code on OpenMV. Thank you!
I was wondering, by the way, is there any way I could import my own classifier xml file. Let's say I want to do Upper Body Detection using an upper body xml, how would I import that? I couldn't find a frontal xml file used for your facial detection, so I don't really know how the classifiers are imported into the code on OpenMV. Thank you!
Re: Script autostart
Hello! I created a cascade file using the cascade_convert.py I found online. So, I placed it in the /home/openmvide folder. I tried to run the code (using the new cascade) as seen on the attached image but it had an error that said it can't find the path. Sorry I know its a basic question... I tried to use its whole path which is /home/uavdlsu/openmvide/haarcascade_mcs_upperbody.cascade but it also did not work.. am I doing something wrong? Thank you
Return to “Technical Discussion”
Who is online
Users browsing this forum: No registered users and 2 guests