I am playing with the machine learning capabilities of the camera, therefore, I’d like to collect positive and negative sample images. Saving them on the SD card seemed to be unstable since if the camera was reset or disconnected, the captured data was lost sometimes. I was looking for a way to save the raw image through serial port. img.save(‘img.bmp’) works fine, but sending it over the serial port and saving on a host machine does not. At the end, the file is different than the one saved on the SD card.
The code on the cam:
... usb = USB_VCP() ... img = sensor.snapshot() # Take a picture and return the image. usb.send(img)
The code on the host:
ser = serial.Serial('/dev/ttyACM0') # open serial port ser.baudrate = 115200 # This is just a simplified version, I am sure the correct section of the data is captured # since data separators are used. data = ser.read(38400) # Read data f = open("img.bmp", 'wb') # open in binary f.write(data) f.close()
Do you have any idea what’s wrong here?