import serial
import time
import cv2
import os
def send_command(command):
ser.write(command.encode('utf-8') + b'\r\n')
time.sleep(1) # Adjust as needed
def read_response():
response = ser.readline().decode('utf-8')
return response.strip()
ser = serial.Serial('COM11', baudrate=9600, timeout=1)
try:
send_command('import os')
send_command('import pyb')
send_command('import sensor')
send_command('sensor.reset()')
time.sleep(2) # Allow time for the sensor to reset
print(read_response()) # Print response after sensor reset
send_command('sensor.set_pixformat(sensor.RGB565)')
send_command('sensor.set_framesize(sensor.QVGA)')
send_command('sensor.skip_frames(time=2000)')
for i in range(6): # Capture four images
send_command('img = sensor.snapshot()')
print(read_response()) # Print response after image capture
send_command('os.sync()')
send_command('img.save("temp/temp{}.jpg")'.format(i)) # Save with different filenames
print(read_response()) # Print response after saving the image
print("Image {} captured and saved to temp{}.jpg".format(i+1, i))
finally:
send_command('pyb.soft_reset()')
ser.close()
time.sleep(4)
Directory containing the images
image_folder = 'E:\\temp'
Output video file name
video_name = 'D:\\output_video4.avi'
Get the list of image filenames in the directory
images = [img for img in os.listdir(image_folder) if img.endswith(".jpg")]
Sort the image filenames to ensure they are in the correct order
images.sort()
Get the dimensions of the first image to use for video size
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape
Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
video = cv2.VideoWriter(video_name, fourcc, 1, (width, height))
Iterate through the images and add them to the video
for image in images:
video.write(cv2.imread(os.path.join(image_folder, image)))
Release the video writer object
video.release()
print(f"Video '{video_name}' created successfully.")
this is the code , i used earlier to take snap and save that to the internal storage of the openmv H7, now but now it is not saving the images to the internal storage, once i connect the camera , i just open the openmv and connect the device to the system, i do test run, after that i run this program in pycharm, First time it works well takes picture and saves it and gives responce and everything, the same if i run second time it work. after that if i run n number of times it wont save any image to defined location.