|
@@ -1,7 +1,10 @@
|
|
|
import cv2
|
|
import cv2
|
|
|
|
|
+import datetime
|
|
|
|
|
+import io
|
|
|
import numpy as np
|
|
import numpy as np
|
|
|
import os
|
|
import os
|
|
|
import threading
|
|
import threading
|
|
|
|
|
+import subprocess
|
|
|
from io import BytesIO
|
|
from io import BytesIO
|
|
|
from PIL import Image
|
|
from PIL import Image
|
|
|
from ppadb.client import Client as AdbClient
|
|
from ppadb.client import Client as AdbClient
|
|
@@ -213,6 +216,39 @@ def non_max_suppression(boxes, overlapThresh):
|
|
|
return boxes[pick].astype("int")
|
|
return boxes[pick].astype("int")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def save_screenshot(path="test"):
|
|
|
|
|
+ # Take a screenshot
|
|
|
|
|
+ result = capture_current_screen()
|
|
|
|
|
+
|
|
|
|
|
+ timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
|
+ image = Image.open(io.BytesIO(result))
|
|
|
|
|
+ jpeg_filename = f"{path}/{timestamp}.jpg"
|
|
|
|
|
+
|
|
|
|
|
+ image = image.convert("RGB") # Convert to RGB mode for JPEG
|
|
|
|
|
+ with open(jpeg_filename, "wb") as fp:
|
|
|
|
|
+ image.save(fp, format="JPEG", quality=85) # Adjust quality as needed
|
|
|
|
|
+ print(f"snap: {jpeg_filename}")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def save_screenshot2(path="test"):
|
|
|
|
|
+ proc = subprocess.Popen(
|
|
|
|
|
+ "adb exec-out screencap -p", shell=True, stdout=subprocess.PIPE
|
|
|
|
|
+ )
|
|
|
|
|
+ image_bytes = proc.stdout.read()
|
|
|
|
|
+ image = cv2.imdecode(np.frombuffer(image_bytes, np.uint8), cv2.IMREAD_COLOR)
|
|
|
|
|
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
|
|
|
|
+
|
|
|
|
|
+ timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
|
+ jpeg_filename = f"{path}/{timestamp}.jpg"
|
|
|
|
|
+
|
|
|
|
|
+ cv2.imwrite(
|
|
|
|
|
+ jpeg_filename,
|
|
|
|
|
+ cv2.cvtColor(image, cv2.COLOR_RGB2BGR),
|
|
|
|
|
+ [int(cv2.IMWRITE_JPEG_QUALITY), 85],
|
|
|
|
|
+ )
|
|
|
|
|
+ print(f"snap: {jpeg_filename}")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
client = AdbClient(host="127.0.0.1", port=5037)
|
|
client = AdbClient(host="127.0.0.1", port=5037)
|
|
|
device = client.device(android_address)
|
|
device = client.device(android_address)
|
|
|
|
|
|