I just put my hand on a OpenMV Cam H7 Plus. I am trying an example(image_transfer_jpg_streaming_as_the_remote_device.py) . As far as i understand (still new to python) , the camera IDE create a virtual serial port and listen for a command. The main python program try to open the port (COM4) and is denied. The probleme, i think, is the port is already in use by the IDE.
How can i get access?
I cant find “image_transfer_jpg_streaming_as_the_controller_device.py” that should go with this exemple.
My goal is to take picture of the bubble on top a seringe and send only the image of the bubble(Macro photography). So doing the image detection and doing some image processing before transfering the image make me choose this camera so i can get high resolution of the bubble.
So here is the code, mostly from the exemple with some minor changes
IDE code
import sensor, image, time, ustruct
from pyb import USB_VCP
usb = USB_VCP()
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000) # Wait for settings take effect.
print(“USB is a Com Port”, usb.isconnected())
while(True):
cmd = usb.recv(4, timeout=5000)
if (cmd == b’snap’):
img = sensor.snapshot().compress()
usb.send(ustruct.pack(“<L”, img.size()))
usb.send(img)
Main python Code
import serial
import struct
port = ‘COM4’
sp = serial.Serial(port, baudrate=115200, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE,
xonxoff=False, rtscts=False, stopbits=serial.STOPBITS_ONE, timeout=None, dsrdtr=True)
sp.setDTR(True) # dsrdtr is ignored on Windows.
sp.write(“snap”)
sp.flush()
size = struct.unpack(‘<L’, sp.read(4))[0]
img = sp.read(size)
sp.close()
with open(“img.jpg”, “w”) as f:
f.write(img)
And in running the main i get the error:
File “C:\Users\Vincent\usbpcvtest\lib\site-packages\serial\serialwin32.py”, line 62, in open raise SerialException(“could not open port {!r}: {!r}”.format(self.portstr, ctypes.WinError())) serial.serialutil.SerialException: could not open port ‘COM4’: PermissionError(13, ‘Access is denied.’, None, 5)
Thanks in advance