-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcamera_controller.py
More file actions
53 lines (39 loc) · 1.94 KB
/
camera_controller.py
File metadata and controls
53 lines (39 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import subprocess
# Construct the ADB command to open the camera and capture a picture
adb_command = ['adb', 'shell', 'am', 'start', '-a', 'android.media.action.IMAGE_CAPTURE']
# Execute the ADB command to open the camera and capture a picture
process = subprocess.Popen(adb_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
# Check if the command to open the camera was successful
if process.returncode == 0:
print('Camera app successfully opened.')
# Wait for a few seconds to allow the camera app to initialize
# Adjust the delay time as needed
import time
time.sleep(5)
# Construct the ADB command to capture the picture
adb_capture_command = ['adb', 'shell', 'input', 'keyevent', 'KEYCODE_CAMERA']
# Execute the ADB command to capture the picture
capture_process = subprocess.Popen(adb_capture_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
capture_output, capture_error = capture_process.communicate()
# Check if the command to capture the picture was successful
if capture_process.returncode == 0:
print('Picture captured successfully.')
else:
print('An error occurred while capturing the picture.')
print('Error:', capture_error.decode('utf-8'))
else:
print('An error occurred while opening the camera app.')
print('Error:', error.decode('utf-8'))
# import subprocess
# # Construct the ADB command to open the camera
# adb_command = ['adb', 'shell', 'am', 'start', '-a', 'android.media.action.IMAGE_CAPTURE']
# # Execute the ADB command to open the camera
# process = subprocess.Popen(adb_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# output, error = process.communicate()
# # Check if the command was successful
# if process.returncode == 0:
# print('Camera app successfully opened.')
# else:
# print('An error occurred while opening the camera app.')
# print('Error:', error.decode('utf-8'))