This commit is contained in:
Jimmy 2023-01-01 05:22:41 +00:00
parent 6a550d5847
commit 6edf6e5815
1 changed files with 70 additions and 12 deletions

82
pi.py Normal file → Executable file
View File

@ -4,19 +4,33 @@ import cv2
from gpiozero import LED, Button
from picamera2 import Picamera2
from time import sleep
import asyncio
import requests
from io import BytesIO
from PIL import Image
import shutil
from random import randint
import numpy as np
import sys
import pyautogui
red = LED(19)
blue = LED(26)
green = LED(13)
button = Button(5)
button2 = Button(2)
button3 = Button(3)
# Grab images as numpy arrays and leave everything else to OpenCV.
x = 1920
y = 1080
x = 512
y = 512
print(pyautogui.size())
x, y = pyautogui.size()
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
#cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.resizeWindow("window", x, y)
picam2 = Picamera2()
capture_config = picam2.create_preview_configuration(main={"size": (x, y),
@ -24,25 +38,69 @@ capture_config = picam2.create_preview_configuration(main={"size": (x, y),
picam2.configure(capture_config)
picam2.start()
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
# cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
while True:
# cv2.resizeWindow("window", x, y)
while True:
im = picam2.capture_array()
cv2.imshow("window", im)
if cv2.waitKey(40) & 0xFF == ord('a') or button.value:
if cv2.waitKey(40) & 0xFF == ord('q'):
sys.exit()
if button2.value:
break
while button.value:
pass
while not button.value:
sleep(0.1)
while not button.value:
pass
color_converted = cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
img=Image.fromarray(color_converted)
byte_io = BytesIO()
img.save(byte_io, 'png')
byte_io.seek(0)
print("-------------------Generating Image----------------------")
r = requests.post(url='http://192.168.1.100:8000?text=into cyborg robot ',
files={
'my_file': (
'1.png',
byte_io,
'image/png'
),
},
stream=True
)
print(r.status_code)
if r.status_code == 200:
byte_io = BytesIO(r.content)
img = Image.open(byte_io)
# img.show()
height_orig = img.height
width_orig = img.width
aspect_ratio = width_orig / height_orig
width_new = x
height_new = int(width_new / aspect_ratio)
img = img.resize((width_new, height_new), 0)
numpy_image=np.array(img)
opencv_image=cv2.cvtColor(numpy_image, cv2.COLOR_RGB2BGR)
cv2.imshow("window", opencv_image)
print("---------------------------------Image Generated-----------------------------")
print("--------------------Sleeping-------------------------")
sleep(10)
print("--------------------Slept----------------------------")
sleep(1)