Tôi có một chiếc GoPro Hero 7 White và gần đây tôi đã phát hiện ra rằng tôi có thể sử dụng nó như một webcam từ xa bằng cách sử dụng gói Python có tênAPI GoPro cho Python, có sẵn tạihttps://github.com/konradit/gopro-py-api.
Đầu tiên cài đặt gói bằng cách sử dụngpip3 install goprocam
sau đó kích hoạt kết nối WiFi trên GoPro.
Điều này làm cho GoPro bắt đầu một mạng WiFi. Kết nối với mạng đó từ máy tính.
Bây giờ bạn đã sẵn sàng viết chương trình Python của mình để làm bất cứ điều gì bạn muốn với webcam.
Nhập khẩuGoProCamera
vàconstants
từgoprocam
:
from goprocam import GoProCamera, constants
Sau đó gọi choGoProCamera.GoPro()
phương pháp lấy đối tượng camera:
gopro = GoProCamera.GoPro(constants.gpcontrol)
Xem tổng quan về trạng thái máy ảnh đang sử dụng
gopro.overview()
Trong trường hợp của tôi, tôi đã in ra cái này:
camera overview
current mode: Photo
current submode: Burst
current video resolution: out of scope
current video framerate: 240
pictures taken: 0
videos taken: 0
videos left: 02:10:44
pictures left: 11257
battery left: Halfway
space left in sd card: 58.04GB
camera SSID: HERO7 White
Is Recording: Not recording - standby
Clients connected: 2
camera model: HERO7 White
firmware version: H18.02.02.10.00
serial number: C3343323864041Now you can use a variety of methods that make the GoPro take actions.
You can take a photo immediately:
gopro.take_photo()
You can take a photo after 2 seconds:
gopro.take_photo(2)
You can shoot a 10-seconds video:
gopro.shoot_video(10)
Or just start recording, with no preset end time, using
gopro.shoot_video()
You can download the last picture or video taken using
gopro.downloadLastMedia()
You can also set a name for the file:
gopro.downloadLastMedia("pic.JPG")
Tip: I ran into a bug that prevented me to download the picture when I called downloadLastMedia()
. I was getting errors that said “Not supported while recording or processing media”. I had to call gopro.getStatusRaw()
before calling downloadLastMedia()
to fix it.
There are many useful methods like
KeepAlive()
to prevent the GoPro to turn off
setZoom()
to set the zoom
downloadAll()
to download all media from the camera
delete("last")
to delete the last media taken
delete("all")
to delete all media
power_off()
power off the camera
power_on()
power on the camera
stream()
to start streaming (haven’t figured it out yet)
You can find many examples here and more documentation here.
The camera is available on IP 10.5.5.9
, with the MAC address AA:BB:CC:DD:EE:FF
.
More python tutorials:
- Introduction to Python
- Installing Python 3 on macOS
- Running Python programs
- Python 2 vs Python 3
- The basics of working with Python
- Python Data Types
- Python Operators
- Python Strings
- Python Booleans
- Python Numbers
- Python, Accepting Input
- Python Control Statements
- Python Lists
- Python Tuples
- Python Sets
- Python Dictionaries
- Python Functions
- Python Objects
- Python Loops
- Python Modules
- Python Classes
- The Python Standard Library
- Debugging Python
- Python variables scope
- Python, accept arguments from command line
- Python Recursion
- Python Nested Functions
- Python Lambda Functions
- Python Closures
- Python Virtual Environments
- Use a GoPro as a remote webcam using Python
- Python, how to create a list from a string
- Python Decorators
- Python Docstrings
- Python Introspection
- Python Annotations
- Python, how to list files and folders in a directory
- Python, how to check if a number is odd or even
- Python, how to get the details of a file
- Python, how to check if a file or directory exists
- Python Exceptions
- Python, how to create a directory
- Python, how to create an empty file
- Python, the `with` statement
- Python, create a network request
- Python, installing 3rd party packages using `pip`
- Python, read the content of a file