import subprocess
import requests
import base64
def capture_image():
# Capture an image using fswebcam command-line tool
subprocess.run(["fswebcam", "-r", "640x480", "--no-banner", "image.jpg"])
# Read the captured image file
with open("image.jpg", "rb") as file:
image_data = file.read()
return image_data
def send_image(image):
# Encode the image as base64
image_base64 = base64.b64encode(image)
# Send the image to the server
url = "http://your-server-url.com/upload" # Replace with your server URL
payload = {"image": image_base64}
response = requests.post(url, data=payload)
# Process the server response
if response.status_code == 200:
print("Image uploaded successfully.")
else:
print("Error uploading the image.")
# Capture an image using fswebcam
captured_image = capture_image()
# Send the image to the server
send_image(captured_image)