diff --git a/docs/gears/camgear/usage.md b/docs/gears/camgear/usage.md index c46ea818c..b92a7fc66 100644 --- a/docs/gears/camgear/usage.md +++ b/docs/gears/camgear/usage.md @@ -28,7 +28,7 @@ limitations under the License. Following is the bare-minimum code you need to get started with CamGear API: -```python +```python linenums="1" # import required libraries from vidgear.gears import CamGear import cv2 @@ -124,7 +124,8 @@ The complete usage example for Dailymotion and Twitch URLs are as follows: ``` === "Dailymotion :fontawesome-brands-dailymotion:" - ```python hl_lines="12-13" + + ```python linenums="1" hl_lines="12-13" # import required libraries from vidgear.gears import CamGear import cv2 @@ -172,7 +173,7 @@ The complete usage example for Dailymotion and Twitch URLs are as follows: !!! warning "If Twitch user is offline, CamGear will throw ValueError." - ```python hl_lines="12-13" + ```python linenums="1" hl_lines="12-13" # import required libraries from vidgear.gears import CamGear import cv2 @@ -274,7 +275,7 @@ The complete usage example is as follows: print(video_metadata["title"]) ``` -```python hl_lines="8-9" +```python linenums="1" hl_lines="8-9" # import required libraries from vidgear.gears import CamGear import cv2 @@ -325,7 +326,7 @@ The complete usage example is as follows: !!! tip "All the supported Source Tweak Parameters can be found [here ➶](../advanced/source_params/#source-tweak-parameters-for-camgear-api)" -```python hl_lines="8-10" +```python linenums="1" hl_lines="8-10" # import required libraries from vidgear.gears import CamGear import cv2 @@ -383,7 +384,7 @@ In following example code, we will start with [**HSV**](https://en.wikipedia.org !!! failure "Any incorrect or None-type value, will immediately revert the colorspace to default i.e. `BGR`." -```python hl_lines="7 30 34 38" +```python linenums="1" hl_lines="7 30 34 38" # import required libraries from vidgear.gears import CamGear import cv2 diff --git a/docs/gears/netgear/advanced/bidirectional_mode.md b/docs/gears/netgear/advanced/bidirectional_mode.md index dfb99fd5f..0deaef448 100644 --- a/docs/gears/netgear/advanced/bidirectional_mode.md +++ b/docs/gears/netgear/advanced/bidirectional_mode.md @@ -96,7 +96,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both sides anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="9 31" +```python linenums="1" hl_lines="9 31" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -151,7 +151,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 18" +```python linenums="1" hl_lines="6 18" # import required libraries from vidgear.gears import NetGear import cv2 @@ -219,7 +219,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="11-17" +```python linenums="1" hl_lines="11-17" # import required libraries from vidgear.gears import NetGear import cv2 @@ -290,73 +290,160 @@ Now, Open the terminal on another Server System _(a Raspberry Pi with Camera Mod !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="25-30" -# import required libraries -from vidgear.gears import VideoGear -from vidgear.gears import NetGear -from vidgear.gears import PiGear +!!! new "Backend PiGear API now fully supports the newer [`picamera2`](https://github.com/raspberrypi/picamera2) python library under the hood for Raspberry Pi :fontawesome-brands-raspberry-pi: camera modules. Follow this [guide ➶](../../installation/pip_install/#picamera2) for its installation." -# add various Picamera tweak parameters to dictionary -options = { - "hflip": True, - "exposure_mode": "auto", - "iso": 800, - "exposure_compensation": 15, - "awb_mode": "horizon", - "sensor_mode": 0, -} +!!! warning "Make sure to [complete Raspberry Pi Camera Hardware-specific settings](https://www.raspberrypi.com/documentation/accessories/camera.html#installing-a-raspberry-pi-camera) prior using this backend, otherwise nothing will work." -# open pi video stream with defined parameters -stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() -# activate Bidirectional mode -options = {"bidirectional_mode": True} +=== "New Picamera2 backend" -# Define NetGear server at given IP address and define parameters -# !!! change following IP address '192.168.x.xxx' with client's IP address !!! -server = NetGear( - address="192.168.x.xxx", - port="5454", - protocol="tcp", - pattern=1, - logging=True, - **options -) + ```python linenums="1" hl_lines="25-30" + # import required libraries + from vidgear.gears import VideoGear + from vidgear.gears import NetGear + from vidgear.gears import PiGear + from libcamera import Transform -# loop over until KeyBoard Interrupted -while True: + # add various Picamera2 API tweaks + options = { + "queue": True, + "buffer_count": 4, + "controls": {"Brightness": 0.5, "ExposureValue": 2.0}, + "transform": Transform(hflip=1), + "auto_align_output_config": True, # auto-align camera configuration + } - try: - # read frames from stream - frame = stream.read() + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() - # check for frame if Nonetype - if frame is None: + # activate Bidirectional mode + options = {"bidirectional_mode": True} + + # Define NetGear server at given IP address and define parameters + # !!! change following IP address '192.168.x.xxx' with client's IP address !!! + server = NetGear( + address="192.168.x.xxx", + port="5454", + protocol="tcp", + pattern=1, + logging=True, + **options + ) + + # loop over until KeyBoard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with the frame here} + + # prepare data to be sent(a simple text in our case) + target_data = "Hello, I am a Server." + + # send frame & data and also receive data from Client + recv_data = server.send(frame, message=target_data) # (1) + + # print data just received from Client + if not (recv_data is None): + print(recv_data) + + except KeyboardInterrupt: break - # {do something with the frame here} + # safely close video stream + stream.stop() - # prepare data to be sent(a simple text in our case) - target_data = "Hello, I am a Server." + # safely close server + server.close() + ``` - # send frame & data and also receive data from Client - recv_data = server.send(frame, message=target_data) # (1) + 1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted as `target_data` in `message` parameter. - # print data just received from Client - if not (recv_data is None): - print(recv_data) + +=== "Legacy Picamera backend" - except KeyboardInterrupt: - break + ??? info "Under the hood, Backend PiGear API _(version `0.3.3` onwards)_ prioritizes the new [`picamera2`](https://github.com/raspberrypi/picamera2) API backend." -# safely close video stream -stream.stop() + However, the API seamlessly switches to the legacy [`picamera`](https://picamera.readthedocs.io/en/release-1.13/index.html) backend, if the `picamera2` library is unavailable or not installed. + + !!! tip "It is advised to enable logging(`logging=True`) to see which backend is being used." -# safely close server -server.close() -``` + !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." + + ```python linenums="1" hl_lines="25-30" + # import required libraries + from vidgear.gears import VideoGear + from vidgear.gears import NetGear + from vidgear.gears import PiGear + + # add various Picamera tweak parameters to dictionary + options = { + "hflip": True, + "exposure_mode": "auto", + "iso": 800, + "exposure_compensation": 15, + "awb_mode": "horizon", + "sensor_mode": 0, + } + + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() + + # activate Bidirectional mode + options = {"bidirectional_mode": True} + + # Define NetGear server at given IP address and define parameters + # !!! change following IP address '192.168.x.xxx' with client's IP address !!! + server = NetGear( + address="192.168.x.xxx", + port="5454", + protocol="tcp", + pattern=1, + logging=True, + **options + ) + + # loop over until KeyBoard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with the frame here} + + # prepare data to be sent(a simple text in our case) + target_data = "Hello, I am a Server." + + # send frame & data and also receive data from Client + recv_data = server.send(frame, message=target_data) # (1) + + # print data just received from Client + if not (recv_data is None): + print(recv_data) + + except KeyboardInterrupt: + break + + # safely close video stream + stream.stop() + + # safely close server + server.close() + ``` + + 1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted as `target_data` in `message` parameter. -1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted as `target_data` in `message` parameter.   @@ -380,7 +467,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="35-45" +```python linenums="1" hl_lines="35-45" # import required libraries from vidgear.gears import NetGear from vidgear.gears.helper import reducer @@ -447,7 +534,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="29" +```python linenums="1" hl_lines="29" # import required libraries from vidgear.gears import NetGear from vidgear.gears.helper import reducer diff --git a/docs/gears/netgear/advanced/compression.md b/docs/gears/netgear/advanced/compression.md index 41ffbf8b7..030ede0d4 100644 --- a/docs/gears/netgear/advanced/compression.md +++ b/docs/gears/netgear/advanced/compression.md @@ -117,7 +117,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both sides anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="11-14" +```python linenums="1" hl_lines="11-14" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -173,7 +173,7 @@ Then open another terminal on the same system and execute the following python c !!! note "If compression is enabled at Server, then Client will automatically enforce Frame Compression with its performance attributes." -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -230,7 +230,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both sides anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7 11" +```python linenums="1" hl_lines="7 11" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -288,7 +288,7 @@ Then open another terminal on the same system and execute the following python c !!! info "Client's end also automatically enforces Server's colorspace, there's no need to define it again." -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -340,7 +340,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="9-15" +```python linenums="1" hl_lines="9-15" # import required libraries from vidgear.gears import NetGear import cv2 @@ -395,7 +395,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="20-25" +```python linenums="1" hl_lines="20-25" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -475,7 +475,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="12-16 42" +```python linenums="1" hl_lines="12-16 42" # import required libraries from vidgear.gears import NetGear from vidgear.gears.helper import reducer @@ -548,7 +548,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="8-12 35" +```python linenums="1" hl_lines="8-12 35" # import required libraries from vidgear.gears import NetGear from vidgear.gears.helper import reducer diff --git a/docs/gears/netgear/advanced/multi_client.md b/docs/gears/netgear/advanced/multi_client.md index 7f1ea5fba..c41241bc9 100644 --- a/docs/gears/netgear/advanced/multi_client.md +++ b/docs/gears/netgear/advanced/multi_client.md @@ -103,7 +103,7 @@ Now, Open the terminal on a Server System _(with a webcam connected to it at ind !!! tip "You can terminate streaming anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="9 16 39-52" +```python linenums="1" hl_lines="9 16 39-52" # import required libraries from vidgear.gears import NetGear from vidgear.gears import CamGear @@ -176,7 +176,7 @@ Now, Open a terminal on another Client System _(where you want to display the in !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 11-17" +```python linenums="1" hl_lines="6 11-17" # import required libraries from vidgear.gears import NetGear import cv2 @@ -233,7 +233,7 @@ Finally, Open a terminal on another Client System _(where you want to display th !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 11-17" +```python linenums="1" hl_lines="6 11-17" # import required libraries from vidgear.gears import NetGear import cv2 @@ -302,7 +302,7 @@ Now, Open the terminal on a Server System _(with a webcam connected to it at ind !!! tip "You can terminate streaming anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -374,7 +374,7 @@ Now, Open a terminal on another Client System _(where you want to display the in !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -430,7 +430,7 @@ Finally, Open a terminal on another Client System _(also, where you want to disp !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -505,77 +505,165 @@ Now, Open the terminal on a Server System _(with a webcam connected to it at ind !!! tip "You can terminate streaming anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="47-60" -# import required libraries -from vidgear.gears import PiGear -from vidgear.gears import NetGear +!!! new "Backend PiGear API now fully supports the newer [`picamera2`](https://github.com/raspberrypi/picamera2) python library under the hood for Raspberry Pi :fontawesome-brands-raspberry-pi: camera modules. Follow this [guide ➶](../../installation/pip_install/#picamera2) for its installation." -# add various Picamera tweak parameters to dictionary -options = { - "hflip": True, - "exposure_mode": "auto", - "iso": 800, - "exposure_compensation": 15, - "awb_mode": "horizon", - "sensor_mode": 0, -} +!!! warning "Make sure to [complete Raspberry Pi Camera Hardware-specific settings](https://www.raspberrypi.com/documentation/accessories/camera.html#installing-a-raspberry-pi-camera) prior using this backend, otherwise nothing will work." -# open pi video stream with defined parameters -stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() -# activate multiclient_mode mode -options = {"multiclient_mode": True} +=== "New Picamera2 backend" -# Define NetGear Client at given IP address and assign list/tuple of all unique Server((5577,5578) in our case) and other parameters -server = NetGear( - address="192.168.x.x", - port=(5577, 5578), - protocol="tcp", - pattern=1, - logging=True, - **options -) # !!! change following IP address '192.168.x.xxx' with yours !!! + ```python linenums="1" hl_lines="47-60" + # import required libraries + from vidgear.gears import PiGear + from vidgear.gears import NetGear -# Define received data dictionary -data_dict = {} + # add various Picamera2 tweak parameters + options = { + "queue": True, + "buffer_count": 4, + "controls": {"Brightness": 0.5, "ExposureValue": 2.0}, + "transform": Transform(hflip=1), + "auto_align_output_config": True, # auto-align camera configuration + } -# loop over until KeyBoard Interrupted -while True: + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() - try: - # read frames from stream - frame = stream.read() + # activate multiclient_mode mode + options = {"multiclient_mode": True} - # check for frame if Nonetype - if frame is None: - break + # Define NetGear Client at given IP address and assign list/tuple of all unique Server((5577,5578) in our case) and other parameters + server = NetGear( + address="192.168.x.x", + port=(5577, 5578), + protocol="tcp", + pattern=1, + logging=True, + **options + ) # !!! change following IP address '192.168.x.xxx' with yours !!! - # {do something with the frame here} + # Define received data dictionary + data_dict = {} - # send frame and also receive data from Client(s) - recv_data = server.send(frame) + # loop over until KeyBoard Interrupted + while True: - # check if valid data received - if not (recv_data is None): - # extract unique port address and its respective data - unique_address, data = recv_data - # update the extracted data in the data dictionary - data_dict[unique_address] = data + try: + # read frames from stream + frame = stream.read() - if data_dict: - # print data just received from Client(s) - for key, value in data_dict.items(): - print("Client at port {} said: {}".format(key, value)) + # check for frame if Nonetype + if frame is None: + break - except KeyboardInterrupt: - break + # {do something with the frame here} -# safely close video stream -stream.stop() + # send frame and also receive data from Client(s) + recv_data = server.send(frame) -# safely close server -server.close() -``` + # check if valid data received + if not (recv_data is None): + # extract unique port address and its respective data + unique_address, data = recv_data + # update the extracted data in the data dictionary + data_dict[unique_address] = data + + if data_dict: + # print data just received from Client(s) + for key, value in data_dict.items(): + print("Client at port {} said: {}".format(key, value)) + + except KeyboardInterrupt: + break + + # safely close video stream + stream.stop() + + # safely close server + server.close() + ``` + +=== "Legacy Picamera backend" + + ??? info "Under the hood, Backend PiGear API _(version `0.3.3` onwards)_ prioritizes the new [`picamera2`](https://github.com/raspberrypi/picamera2) API backend." + + However, the API seamlessly switches to the legacy [`picamera`](https://picamera.readthedocs.io/en/release-1.13/index.html) backend, if the `picamera2` library is unavailable or not installed. + + !!! tip "It is advised to enable logging(`logging=True`) to see which backend is being used." + + !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." + + ```python linenums="1" hl_lines="47-60" + # import required libraries + from vidgear.gears import PiGear + from vidgear.gears import NetGear + + # add various Picamera tweak parameters to dictionary + options = { + "hflip": True, + "exposure_mode": "auto", + "iso": 800, + "exposure_compensation": 15, + "awb_mode": "horizon", + "sensor_mode": 0, + } + + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() + + # activate multiclient_mode mode + options = {"multiclient_mode": True} + + # Define NetGear Client at given IP address and assign list/tuple of all unique Server((5577,5578) in our case) and other parameters + server = NetGear( + address="192.168.x.x", + port=(5577, 5578), + protocol="tcp", + pattern=1, + logging=True, + **options + ) # !!! change following IP address '192.168.x.xxx' with yours !!! + + # Define received data dictionary + data_dict = {} + + # loop over until KeyBoard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with the frame here} + + # send frame and also receive data from Client(s) + recv_data = server.send(frame) + + # check if valid data received + if not (recv_data is None): + # extract unique port address and its respective data + unique_address, data = recv_data + # update the extracted data in the data dictionary + data_dict[unique_address] = data + + if data_dict: + # print data just received from Client(s) + for key, value in data_dict.items(): + print("Client at port {} said: {}".format(key, value)) + + except KeyboardInterrupt: + break + + # safely close video stream + stream.stop() + + # safely close server + server.close() + ```   @@ -588,7 +676,7 @@ Now, Open a terminal on another Client System _(where you want to display the in !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="27" +```python linenums="1" hl_lines="27" # import required libraries from vidgear.gears import NetGear import cv2 @@ -649,7 +737,7 @@ Finally, Open a terminal on another Client System _(also, where you want to disp !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="27" +```python linenums="1" hl_lines="27" # import required libraries from vidgear.gears import NetGear import cv2 @@ -732,83 +820,178 @@ Now, Open the terminal on a Server System _(with a webcam connected to it at ind !!! tip "You can terminate streaming anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="19 48-64" -# import required libraries -from vidgear.gears import PiGear -from vidgear.gears import NetGear +!!! new "Backend PiGear API now fully supports the newer [`picamera2`](https://github.com/raspberrypi/picamera2) python library under the hood for Raspberry Pi :fontawesome-brands-raspberry-pi: camera modules. Follow this [guide ➶](../../installation/pip_install/#picamera2) for its installation." -# add various Picamera tweak parameters to dictionary -options = { - "hflip": True, - "exposure_mode": "auto", - "iso": 800, - "exposure_compensation": 15, - "awb_mode": "horizon", - "sensor_mode": 0, -} +!!! warning "Make sure to [complete Raspberry Pi Camera Hardware-specific settings](https://www.raspberrypi.com/documentation/accessories/camera.html#installing-a-raspberry-pi-camera) prior using this backend, otherwise nothing will work." -# open pi video stream with defined parameters -stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() -# activate both multiclient and bidirectional modes -options = {"multiclient_mode": True, "bidirectional_mode": True} +=== "New Picamera2 backend" -# Define NetGear Client at given IP address and assign list/tuple of -# all unique Server((5577,5578) in our case) and other parameters -server = NetGear( - address="192.168.x.x", - port=(5577, 5578), - protocol="tcp", - pattern=1, - logging=True, - **options -) # !!! change following IP address '192.168.x.xxx' with yours !!! + ```python linenums="1" hl_lines="19 48-64" + # import required libraries + from vidgear.gears import PiGear + from vidgear.gears import NetGear + from libcamera import Transform -# Define received data dictionary -data_dict = {} + # add various Picamera2 tweak parameters + options = { + "queue": True, + "buffer_count": 4, + "controls": {"Brightness": 0.5, "ExposureValue": 2.0}, + "transform": Transform(hflip=1), + "auto_align_output_config": True, # auto-align camera configuration + } -# loop over until KeyBoard Interrupted -while True: + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() - try: - # read frames from stream - frame = stream.read() + # activate both multiclient and bidirectional modes + options = {"multiclient_mode": True, "bidirectional_mode": True} - # check for frame if Nonetype - if frame is None: - break + # Define NetGear Client at given IP address and assign list/tuple of + # all unique Server((5577,5578) in our case) and other parameters + server = NetGear( + address="192.168.x.x", + port=(5577, 5578), + protocol="tcp", + pattern=1, + logging=True, + **options + ) # !!! change following IP address '192.168.x.xxx' with yours !!! - # {do something with the frame here} + # Define received data dictionary + data_dict = {} - # prepare data to be sent(a simple text in our case) - target_data = "Hello, I am a Server." + # loop over until KeyBoard Interrupted + while True: - # send frame & data and also receive data from Client(s) - recv_data = server.send(frame, message=target_data) # (1) + try: + # read frames from stream + frame = stream.read() - # check if valid data received - if not (recv_data is None): - # extract unique port address and its respective data - unique_address, data = recv_data - # update the extracted data in the data dictionary - data_dict[unique_address] = data + # check for frame if Nonetype + if frame is None: + break - if data_dict: - # print data just received from Client(s) - for key, value in data_dict.items(): - print("Client at port {} said: {}".format(key, value)) + # {do something with the frame here} - except KeyboardInterrupt: - break + # prepare data to be sent(a simple text in our case) + target_data = "Hello, I am a Server." -# safely close video stream -stream.stop() + # send frame & data and also receive data from Client(s) + recv_data = server.send(frame, message=target_data) # (1) -# safely close server -server.close() -``` + # check if valid data received + if not (recv_data is None): + # extract unique port address and its respective data + unique_address, data = recv_data + # update the extracted data in the data dictionary + data_dict[unique_address] = data + + if data_dict: + # print data just received from Client(s) + for key, value in data_dict.items(): + print("Client at port {} said: {}".format(key, value)) + + except KeyboardInterrupt: + break + + # safely close video stream + stream.stop() + + # safely close server + server.close() + ``` + + 1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted as `target_data` in `message` parameter. + +=== "Legacy Picamera backend" + + ??? info "Under the hood, Backend PiGear API _(version `0.3.3` onwards)_ prioritizes the new [`picamera2`](https://github.com/raspberrypi/picamera2) API backend." + + However, the API seamlessly switches to the legacy [`picamera`](https://picamera.readthedocs.io/en/release-1.13/index.html) backend, if the `picamera2` library is unavailable or not installed. + + !!! tip "It is advised to enable logging(`logging=True`) to see which backend is being used." + + !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." + + ```python linenums="1" hl_lines="19 48-64" + # import required libraries + from vidgear.gears import PiGear + from vidgear.gears import NetGear + + # add various Picamera tweak parameters to dictionary + options = { + "hflip": True, + "exposure_mode": "auto", + "iso": 800, + "exposure_compensation": 15, + "awb_mode": "horizon", + "sensor_mode": 0, + } + + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() + + # activate both multiclient and bidirectional modes + options = {"multiclient_mode": True, "bidirectional_mode": True} + + # Define NetGear Client at given IP address and assign list/tuple of + # all unique Server((5577,5578) in our case) and other parameters + server = NetGear( + address="192.168.x.x", + port=(5577, 5578), + protocol="tcp", + pattern=1, + logging=True, + **options + ) # !!! change following IP address '192.168.x.xxx' with yours !!! + + # Define received data dictionary + data_dict = {} + + # loop over until KeyBoard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with the frame here} + + # prepare data to be sent(a simple text in our case) + target_data = "Hello, I am a Server." + + # send frame & data and also receive data from Client(s) + recv_data = server.send(frame, message=target_data) # (1) + + # check if valid data received + if not (recv_data is None): + # extract unique port address and its respective data + unique_address, data = recv_data + # update the extracted data in the data dictionary + data_dict[unique_address] = data + + if data_dict: + # print data just received from Client(s) + for key, value in data_dict.items(): + print("Client at port {} said: {}".format(key, value)) + + except KeyboardInterrupt: + break + + # safely close video stream + stream.stop() + + # safely close server + server.close() + ``` -1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted as `target_data` in `message` parameter. + 1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted as `target_data` in `message` parameter.   @@ -822,7 +1005,7 @@ Now, Open a terminal on another Client System _(where you want to display the in !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 23-34 42-44" +```python linenums="1" hl_lines="6 23-34 42-44" # import required libraries from vidgear.gears import NetGear import cv2 @@ -894,7 +1077,7 @@ Finally, Open a terminal on another Client System _(also, where you want to disp !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 23-34 42-44" +```python linenums="1" hl_lines="6 23-34 42-44" # import required libraries from vidgear.gears import NetGear import cv2 diff --git a/docs/gears/netgear/advanced/multi_server.md b/docs/gears/netgear/advanced/multi_server.md index 761ad0823..205c31c57 100644 --- a/docs/gears/netgear/advanced/multi_server.md +++ b/docs/gears/netgear/advanced/multi_server.md @@ -101,7 +101,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7 14 40-52" +```python linenums="1" hl_lines="7 14 40-52" # import required libraries from vidgear.gears import NetGear from imutils import build_montages # (1) @@ -184,7 +184,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="9 14" +```python linenums="1" hl_lines="9 14" # import libraries from vidgear.gears import NetGear from vidgear.gears import CamGear @@ -237,7 +237,7 @@ Finally, Open the terminal on another Server System _(also with a webcam connect !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="9 14" +```python linenums="1" hl_lines="9 14" # import libraries from vidgear.gears import NetGear from vidgear.gears import CamGear @@ -300,7 +300,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear from imutils import build_montages # (1) @@ -381,7 +381,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import libraries from vidgear.gears import NetGear import cv2 @@ -434,7 +434,7 @@ Finally, Open the terminal on another Server System _(also with a webcam connect !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import libraries from vidgear.gears import NetGear import cv2 @@ -503,7 +503,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="38-61" +```python linenums="1" hl_lines="38-61" # import required libraries from vidgear.gears import NetGear from imutils import build_montages # (1) @@ -595,7 +595,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="40" +```python linenums="1" hl_lines="40" # import libraries from vidgear.gears import NetGear from vidgear.gears import VideoGear @@ -660,67 +660,146 @@ Finally, Open the terminal on another Server System _(this time a Raspberry Pi w !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="50" -# import libraries -from vidgear.gears import NetGear -from vidgear.gears import PiGear -import cv2 +!!! new "Backend PiGear API now fully supports the newer [`picamera2`](https://github.com/raspberrypi/picamera2) python library under the hood for Raspberry Pi :fontawesome-brands-raspberry-pi: camera modules. Follow this [guide ➶](../../installation/pip_install/#picamera2) for its installation." -# add various Picamera tweak parameters to dictionary -options = { - "hflip": True, - "exposure_mode": "auto", - "iso": 800, - "exposure_compensation": 15, - "awb_mode": "horizon", - "sensor_mode": 0, -} +!!! warning "Make sure to [complete Raspberry Pi Camera Hardware-specific settings](https://www.raspberrypi.com/documentation/accessories/camera.html#installing-a-raspberry-pi-camera) prior using this backend, otherwise nothing will work." -# open pi video stream with defined parameters -stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() -# activate multiserver_mode -options = {"multiserver_mode": True} +=== "New Picamera2 backend" -# Define NetGear Server at Client's IP address and assign a unique port address and other parameters -# !!! change following IP address '192.168.x.xxx' with yours !!! -server = NetGear( - address="192.168.1.xxx", - port="5578", - protocol="tcp", - pattern=1, - logging=True, - **options -) + ```python linenums="1" hl_lines="50" + # import libraries + from vidgear.gears import NetGear + from vidgear.gears import PiGear + from libcamera import Transform + import cv2 -# loop over until Keyboard Interrupted -while True: + # add various Picamera tweak parameters to dictionary + options = { + "queue": True, + "buffer_count": 4, + "controls": {"Brightness": 0.5, "ExposureValue": 2.0}, + "transform": Transform(hflip=1), + "auto_align_output_config": True, # auto-align camera configuration + } - try: - # read frames from stream - frame = stream.read() + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() - # check for frame if Nonetype - if frame is None: + # activate multiserver_mode + options = {"multiserver_mode": True} + + # Define NetGear Server at Client's IP address and assign a unique port address and other parameters + # !!! change following IP address '192.168.x.xxx' with yours !!! + server = NetGear( + address="192.168.1.xxx", + port="5578", + protocol="tcp", + pattern=1, + logging=True, + **options + ) + + # loop over until Keyboard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with frame and data(to be sent) here} + + # let's prepare a text string as data + text = "I'm Server-2 at Port: 5578" + + # send frame and data through server + server.send(frame, message=text) + + except KeyboardInterrupt: break - # {do something with frame and data(to be sent) here} + # safely close video stream. + stream.stop() - # let's prepare a text string as data - text = "I'm Server-2 at Port: 5578" + # safely close server + server.close() + ``` + +=== "Legacy Picamera backend" - # send frame and data through server - server.send(frame, message=text) + ??? info "Under the hood, Backend PiGear API _(version `0.3.3` onwards)_ prioritizes the new [`picamera2`](https://github.com/raspberrypi/picamera2) API backend." - except KeyboardInterrupt: - break + However, the API seamlessly switches to the legacy [`picamera`](https://picamera.readthedocs.io/en/release-1.13/index.html) backend, if the `picamera2` library is unavailable or not installed. + + !!! tip "It is advised to enable logging(`logging=True`) to see which backend is being used." -# safely close video stream. -stream.stop() + !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." -# safely close server -server.close() -``` + ```python linenums="1" hl_lines="50" + # import libraries + from vidgear.gears import NetGear + from vidgear.gears import PiGear + import cv2 + + # add various Picamera tweak parameters to dictionary + options = { + "hflip": True, + "exposure_mode": "auto", + "iso": 800, + "exposure_compensation": 15, + "awb_mode": "horizon", + "sensor_mode": 0, + } + + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() + + # activate multiserver_mode + options = {"multiserver_mode": True} + + # Define NetGear Server at Client's IP address and assign a unique port address and other parameters + # !!! change following IP address '192.168.x.xxx' with yours !!! + server = NetGear( + address="192.168.1.xxx", + port="5578", + protocol="tcp", + pattern=1, + logging=True, + **options + ) + + # loop over until Keyboard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with frame and data(to be sent) here} + + # let's prepare a text string as data + text = "I'm Server-2 at Port: 5578" + + # send frame and data through server + server.send(frame, message=text) + + except KeyboardInterrupt: + break + + # safely close video stream. + stream.stop() + + # safely close server + server.close() + ```   @@ -753,7 +832,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7 27-31 38 41-64" +```python linenums="1" hl_lines="7 27-31 38 41-64" # import required libraries from vidgear.gears import NetGear from imutils import build_montages # (1) @@ -847,7 +926,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="10 36-44" +```python linenums="1" hl_lines="10 36-44" # import libraries from vidgear.gears import NetGear from vidgear.gears import VideoGear @@ -915,71 +994,154 @@ Finally, Open the terminal on another Server System _(this time a Raspberry Pi w !!! tip "You can terminate stream anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="20 46-54" -# import libraries -from vidgear.gears import NetGear -from vidgear.gears import PiGear -import cv2 +!!! new "Backend PiGear API now fully supports the newer [`picamera2`](https://github.com/raspberrypi/picamera2) python library under the hood for Raspberry Pi :fontawesome-brands-raspberry-pi: camera modules. Follow this [guide ➶](../../installation/pip_install/#picamera2) for its installation." -# add various Picamera tweak parameters to dictionary -options = { - "hflip": True, - "exposure_mode": "auto", - "iso": 800, - "exposure_compensation": 15, - "awb_mode": "horizon", - "sensor_mode": 0, -} +!!! warning "Make sure to [complete Raspberry Pi Camera Hardware-specific settings](https://www.raspberrypi.com/documentation/accessories/camera.html#installing-a-raspberry-pi-camera) prior using this backend, otherwise nothing will work." -# open pi video stream with defined parameters -stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() -# activate both multiserver and bidirectional modes -options = {"multiserver_mode": True, "bidirectional_mode": True} +=== "New Picamera2 backend" -# Define NetGear Server at Client's IP address and assign a unique port address and other parameters -# !!! change following IP address '192.168.x.xxx' with yours !!! -server = NetGear( - address="192.168.1.xxx", - port="5578", - protocol="tcp", - pattern=1, - logging=True, - **options -) + ```python linenums="1" hl_lines="20 46-54" + # import libraries + from vidgear.gears import NetGear + from vidgear.gears import PiGear + from libcamera import Transform + import cv2 -# loop over until Keyboard Interrupted -while True: + # add various Picamera2 tweak parameters + options = { + "queue": True, + "buffer_count": 4, + "controls": {"Brightness": 0.5, "ExposureValue": 2.0}, + "transform": Transform(hflip=1), + "auto_align_output_config": True, # auto-align camera configuration + } - try: - # read frames from stream - frame = stream.read() + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() - # check for frame if Nonetype - if frame is None: + # activate both multiserver and bidirectional modes + options = {"multiserver_mode": True, "bidirectional_mode": True} + + # Define NetGear Server at Client's IP address and assign a unique port address and other parameters + # !!! change following IP address '192.168.x.xxx' with yours !!! + server = NetGear( + address="192.168.1.xxx", + port="5578", + protocol="tcp", + pattern=1, + logging=True, + **options + ) + + # loop over until Keyboard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with frame and data(to be sent) here} + + # let's prepare a text string as data + target_data = "I'm Server-2 at Port: 5578" + + # send frame & data and also receive data from Client + recv_data = server.send(frame, message=target_data) # (1) + + # print data just received from Client + if not (recv_data is None): + print(recv_data) + + except KeyboardInterrupt: break - # {do something with frame and data(to be sent) here} + # safely close video stream. + stream.stop() - # let's prepare a text string as data - target_data = "I'm Server-2 at Port: 5578" + # safely close server + server.close() + ``` + +=== "Legacy Picamera backend" - # send frame & data and also receive data from Client - recv_data = server.send(frame, message=target_data) # (1) + ??? info "Under the hood, Backend PiGear API _(version `0.3.3` onwards)_ prioritizes the new [`picamera2`](https://github.com/raspberrypi/picamera2) API backend." - # print data just received from Client - if not (recv_data is None): - print(recv_data) + However, the API seamlessly switches to the legacy [`picamera`](https://picamera.readthedocs.io/en/release-1.13/index.html) backend, if the `picamera2` library is unavailable or not installed. + + !!! tip "It is advised to enable logging(`logging=True`) to see which backend is being used." - except KeyboardInterrupt: - break + !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." -# safely close video stream. -stream.stop() + ```python linenums="1" hl_lines="20 46-54" + # import libraries + from vidgear.gears import NetGear + from vidgear.gears import PiGear + import cv2 -# safely close server -server.close() -``` + # add various Picamera tweak parameters to dictionary + options = { + "hflip": True, + "exposure_mode": "auto", + "iso": 800, + "exposure_compensation": 15, + "awb_mode": "horizon", + "sensor_mode": 0, + } + + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() + + # activate both multiserver and bidirectional modes + options = {"multiserver_mode": True, "bidirectional_mode": True} + + # Define NetGear Server at Client's IP address and assign a unique port address and other parameters + # !!! change following IP address '192.168.x.xxx' with yours !!! + server = NetGear( + address="192.168.1.xxx", + port="5578", + protocol="tcp", + pattern=1, + logging=True, + **options + ) + + # loop over until Keyboard Interrupted + while True: + + try: + # read frames from stream + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with frame and data(to be sent) here} + + # let's prepare a text string as data + target_data = "I'm Server-2 at Port: 5578" + + # send frame & data and also receive data from Client + recv_data = server.send(frame, message=target_data) # (1) + + # print data just received from Client + if not (recv_data is None): + print(recv_data) + + except KeyboardInterrupt: + break + + # safely close video stream. + stream.stop() + + # safely close server + server.close() + ``` 1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted as `target_data` in `message` parameter. diff --git a/docs/gears/netgear/advanced/secure_mode.md b/docs/gears/netgear/advanced/secure_mode.md index fa225e25c..2f1dddaed 100644 --- a/docs/gears/netgear/advanced/secure_mode.md +++ b/docs/gears/netgear/advanced/secure_mode.md @@ -131,7 +131,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both sides anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="9" +```python linenums="1" hl_lines="9" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -177,7 +177,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6" +```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import NetGear import cv2 @@ -233,7 +233,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 11-17" +```python linenums="1" hl_lines="6 11-17" # import required libraries from vidgear.gears import NetGear import cv2 @@ -292,7 +292,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7 15-20" +```python linenums="1" hl_lines="7 15-20" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear diff --git a/docs/gears/netgear/advanced/ssh_tunnel.md b/docs/gears/netgear/advanced/ssh_tunnel.md index af4609427..82e52ef80 100644 --- a/docs/gears/netgear/advanced/ssh_tunnel.md +++ b/docs/gears/netgear/advanced/ssh_tunnel.md @@ -239,7 +239,7 @@ Open a terminal on Client System _(A Regular PC where you want to display the in !!! info "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7" +```python linenums="1" hl_lines="7" # import required libraries from vidgear.gears import NetGear import cv2 @@ -292,7 +292,7 @@ Now, Open the terminal on Remote Server System _(A Raspberry Pi with a webcam co !!! info "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="8-9 17" +```python linenums="1" hl_lines="8-9 17" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear diff --git a/docs/gears/netgear/usage.md b/docs/gears/netgear/usage.md index f5f1ec722..5f8614fdd 100644 --- a/docs/gears/netgear/usage.md +++ b/docs/gears/netgear/usage.md @@ -45,7 +45,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both sides anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -89,7 +89,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -137,7 +137,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 11-17" +```python linenums="1" hl_lines="6 11-17" # import required libraries from vidgear.gears import NetGear import cv2 @@ -192,7 +192,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 14-19" +```python linenums="1" hl_lines="6 14-19" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -254,7 +254,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -309,7 +309,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -371,7 +371,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear import cv2 @@ -426,7 +426,7 @@ Now, Open the terminal on another Server System _(let's say you want to transmit !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import ScreenGear from vidgear.gears import NetGear diff --git a/docs/gears/netgear_async/advanced/bidirectional_mode.md b/docs/gears/netgear_async/advanced/bidirectional_mode.md index ba1f88e3f..b5b38c961 100644 --- a/docs/gears/netgear_async/advanced/bidirectional_mode.md +++ b/docs/gears/netgear_async/advanced/bidirectional_mode.md @@ -87,7 +87,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate both sides anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 33 40 53" +```python linenums="1" hl_lines="6 33 40 53" # import library from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio @@ -163,7 +163,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 15 31" +```python linenums="1" hl_lines="6 15 31" # import libraries from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio @@ -233,7 +233,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="11-17" +```python linenums="1" hl_lines="11-17" # import libraries from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio @@ -305,96 +305,202 @@ Now, Open the terminal on another Server System _(a Raspberry Pi with Camera Mod !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="12-18" -# import library -from vidgear.gears.asyncio import NetGear_Async -from vidgear.gears import VideoGear -import cv2, asyncio +!!! new "Backend PiGear API now fully supports the newer [`picamera2`](https://github.com/raspberrypi/picamera2) python library under the hood for Raspberry Pi :fontawesome-brands-raspberry-pi: camera modules. Follow this [guide ➶](../../installation/pip_install/#picamera2) for its installation." -# activate Bidirectional mode -options = {"bidirectional_mode": True} +!!! warning "Make sure to [complete Raspberry Pi Camera Hardware-specific settings](https://www.raspberrypi.com/documentation/accessories/camera.html#installing-a-raspberry-pi-camera) prior using this backend, otherwise nothing will work." -# initialize Server without any source at given IP address and define parameters -# !!! change following IP address '192.168.x.xxx' with client's IP address !!! -server = NetGear_Async( - source=None, - address="192.168.x.xxx", - port="5454", - protocol="tcp", - pattern=1, - logging=True, - **options -) +=== "New Picamera2 backend" -# Create a async frame generator as custom source -async def my_frame_generator(): + ```python linenums="1" hl_lines="13-19 23-67 74" + # import libs + from vidgear.gears.asyncio import NetGear_Async + from vidgear.gears import VideoGear + from libcamera import Transform + import cv2, asyncio - # !!! define your own video source here !!! - # Open any video stream such as live webcam - # video stream on first index(i.e. 0) device - # add various Picamera tweak parameters to dictionary - options = { - "hflip": True, - "exposure_mode": "auto", - "iso": 800, - "exposure_compensation": 15, - "awb_mode": "horizon", - "sensor_mode": 0, - } - - # open pi video stream with defined parameters - stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() + # activate Bidirectional mode + options = {"bidirectional_mode": True} - # loop over stream until its terminated - while True: - # read frames - frame = stream.read() + # initialize Server without any source at given IP address and define parameters + # !!! change following IP address '192.168.x.xxx' with client's IP address !!! + server = NetGear_Async( + source=None, + address="192.168.x.xxx", + port="5454", + protocol="tcp", + pattern=1, + logging=True, + **options + ) - # check for frame if Nonetype - if frame is None: - break + # Create a async frame generator as custom source + async def my_frame_generator(): - # {do something with the frame to be sent here} + # !!! define your own video source below !!! - # prepare data to be sent(a simple text in our case) - target_data = "Hello, I am a Server." + # define various Picamera2 tweak parameters + options = { + "queue": True, + "buffer_count": 4, + "controls": {"Brightness": 0.5, "ExposureValue": 2.0}, + "transform": Transform(hflip=1), + "auto_align_output_config": True, # auto-align camera configuration + } - # receive data from Client - recv_data = await server.transceive_data() + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() - # print data just received from Client - if not (recv_data is None): - print(recv_data) + # loop over stream until its terminated + while True: + # read frames + frame = stream.read() - # send our frame & data - yield (target_data, frame) # (1) + # check for frame if Nonetype + if frame is None: + break - # sleep for sometime - await asyncio.sleep(0) + # {do something with the frame to be sent here} + + # prepare data to be sent(a simple text in our case) + target_data = "Hello, I am a Server." + + # receive data from Client + recv_data = await server.transceive_data() + + # print data just received from Client + if not (recv_data is None): + print(recv_data) + + # send our frame & data + yield (target_data, frame) # (1) + + # sleep for sometime + await asyncio.sleep(0) + + # safely close video stream + stream.stop() + + + if __name__ == "__main__": + # set event loop + asyncio.set_event_loop(server.loop) + # Add your custom source generator to Server configuration + server.config["generator"] = my_frame_generator() + # Launch the Server + server.launch() + try: + # run your main function task until it is complete + server.loop.run_until_complete(server.task) + except (KeyboardInterrupt, SystemExit): + # wait for interrupts + pass + finally: + # finally close the server + server.close() + ``` + + 1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted in `target_data`. + +=== "Legacy Picamera backend" + + ??? info "Under the hood, Backend PiGear API _(version `0.3.3` onwards)_ prioritizes the new [`picamera2`](https://github.com/raspberrypi/picamera2) API backend." + + However, the API seamlessly switches to the legacy [`picamera`](https://picamera.readthedocs.io/en/release-1.13/index.html) backend, if the `picamera2` library is unavailable or not installed. - # safely close video stream - stream.stop() + !!! tip "It is advised to enable logging(`logging=True`) to see which backend is being used." + !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." -if __name__ == "__main__": - # set event loop - asyncio.set_event_loop(server.loop) - # Add your custom source generator to Server configuration - server.config["generator"] = my_frame_generator() - # Launch the Server - server.launch() - try: - # run your main function task until it is complete - server.loop.run_until_complete(server.task) - except (KeyboardInterrupt, SystemExit): - # wait for interrupts - pass - finally: - # finally close the server - server.close() -``` -1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted in `target_data`. + ```python linenums="1" hl_lines="12-18 22-67 74" + # import library + from vidgear.gears.asyncio import NetGear_Async + from vidgear.gears import VideoGear + import cv2, asyncio + + # activate Bidirectional mode + options = {"bidirectional_mode": True} + + # initialize Server without any source at given IP address and define parameters + # !!! change following IP address '192.168.x.xxx' with client's IP address !!! + server = NetGear_Async( + source=None, + address="192.168.x.xxx", + port="5454", + protocol="tcp", + pattern=1, + logging=True, + **options + ) + + # Create a async frame generator as custom source + async def my_frame_generator(): + + # !!! define your own video source below !!! + + # define various Picamera tweak parameters + options = { + "hflip": True, + "exposure_mode": "auto", + "iso": 800, + "exposure_compensation": 15, + "awb_mode": "horizon", + "sensor_mode": 0, + } + + # open pi video stream with defined parameters + stream = PiGear(resolution=(640, 480), framerate=60, logging=True, **options).start() + + # loop over stream until its terminated + while True: + # read frames + frame = stream.read() + + # check for frame if Nonetype + if frame is None: + break + + # {do something with the frame to be sent here} + + # prepare data to be sent(a simple text in our case) + target_data = "Hello, I am a Server." + + # receive data from Client + recv_data = await server.transceive_data() + + # print data just received from Client + if not (recv_data is None): + print(recv_data) + + # send our frame & data + yield (target_data, frame) # (1) + + # sleep for sometime + await asyncio.sleep(0) + + # safely close video stream + stream.stop() + + + if __name__ == "__main__": + # set event loop + asyncio.set_event_loop(server.loop) + # Add your custom source generator to Server configuration + server.config["generator"] = my_frame_generator() + # Launch the Server + server.launch() + try: + # run your main function task until it is complete + server.loop.run_until_complete(server.task) + except (KeyboardInterrupt, SystemExit): + # wait for interrupts + pass + finally: + # finally close the server + server.close() + ``` + + 1. :warning: Everything except [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype data is accepted in `target_data`.   @@ -420,7 +526,7 @@ Open your favorite terminal and execute the following python code: !!! alert "Server end can only send [numpy.ndarray](https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy-ndarray) datatype as frame but not as data." -```python hl_lines="8 33-48 54 67" +```python linenums="1" hl_lines="8 33-48 54 67" # import library from vidgear.gears.asyncio import NetGear_Async from vidgear.gears.asyncio.helper import reducer @@ -512,7 +618,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7 18 34-43" +```python linenums="1" hl_lines="7 18 34-43" # import libraries from vidgear.gears.asyncio import NetGear_Async from vidgear.gears.asyncio.helper import reducer diff --git a/docs/gears/netgear_async/usage.md b/docs/gears/netgear_async/usage.md index 351bc6d01..7d44db1ef 100644 --- a/docs/gears/netgear_async/usage.md +++ b/docs/gears/netgear_async/usage.md @@ -51,7 +51,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 13" +```python linenums="1" hl_lines="6 13" # import libraries from vidgear.gears.asyncio import NetGear_Async import asyncio @@ -81,7 +81,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="6 9-20 27" +```python linenums="1" hl_lines="6 9-20 27" # import libraries from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio @@ -134,7 +134,7 @@ Open a terminal on Client System _(where you want to display the input frames re !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7-12" +```python linenums="1" hl_lines="7-12" # import libraries from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio @@ -189,7 +189,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7-12" +```python linenums="1" hl_lines="7-12" # import libraries from vidgear.gears.asyncio import NetGear_Async import asyncio @@ -233,7 +233,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="14-31 38" +```python linenums="1" hl_lines="14-31 38" # import library from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio @@ -349,7 +349,7 @@ Open your favorite terminal and execute the following python code: !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="7" +```python linenums="1" hl_lines="7" # import libraries from vidgear.gears.asyncio import NetGear_Async import asyncio @@ -381,7 +381,7 @@ Then open another terminal on the same system and execute the following python c !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python hl_lines="20" +```python linenums="1" hl_lines="20" # import libraries from vidgear.gears.asyncio import NetGear_Async from vidgear.gears import WriteGear diff --git a/docs/gears/pigear/usage.md b/docs/gears/pigear/usage.md index c47791bca..4cbae0e1e 100644 --- a/docs/gears/pigear/usage.md +++ b/docs/gears/pigear/usage.md @@ -71,7 +71,7 @@ Following is the bare-minimum code you need to get started with PiGear API: export LIBCAMERA_LOG_LEVELS=2 ``` -```python +```python linenums="1" # import required libraries from vidgear.gears import PiGear import cv2 @@ -151,7 +151,7 @@ stream.stop() !!! example "PiGear also support changing parameter at runtime. Checkout this bonus example [here ➶](../../../help/pigear_ex/#dynamically-adjusting-raspberry-pi-camera-parameters-at-runtime-in-pigear-api)" - ```python hl_lines="3 9-14" + ```python linenums="1" hl_lines="3 9-14" # import required libraries from vidgear.gears import PiGear from libcamera import Transform @@ -212,7 +212,7 @@ stream.stop() !!! example "PiGear also support changing parameter at runtime. Checkout this bonus example [here ➶](../../../help/pigear_ex/#dynamically-adjusting-raspberry-pi-camera-parameters-at-runtime-in-pigear-api)" - ```python hl_lines="8-13" + ```python linenums="1" hl_lines="8-13" # import required libraries from vidgear.gears import PiGear import cv2 @@ -272,7 +272,7 @@ In following example code, we will start with [**HSV**](https://en.wikipedia.org !!! warning "Any incorrect or None-Type value will immediately revert the colorspace to default _(i.e. `BGR`)_." -```python hl_lines="9 35 39 43" +```python linenums="1" hl_lines="9 35 39 43" # import required libraries from vidgear.gears import PiGear import cv2 @@ -336,7 +336,7 @@ PiGear can be easily used with WriteGear API directly without any compatibility === "New Picamera2 backend" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import PiGear from vidgear.gears import WriteGear @@ -406,7 +406,7 @@ PiGear can be easily used with WriteGear API directly without any compatibility !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../params/#b-user-defined-parameters) user-defined optional parameter boolean attribute." - ```python + ```python linenums="1" # import required libraries from vidgear.gears import PiGear from vidgear.gears import WriteGear diff --git a/docs/gears/screengear/usage.md b/docs/gears/screengear/usage.md index 6058b93c9..9587f10dd 100644 --- a/docs/gears/screengear/usage.md +++ b/docs/gears/screengear/usage.md @@ -36,7 +36,7 @@ limitations under the License. Following is the bare-minimum code you need to get started with ScreenGear API: -```python +```python linenums="1" # import required libraries from vidgear.gears import ScreenGear import cv2 @@ -94,7 +94,7 @@ ScreenGear API provides us the flexibility to directly set the dimensions of cap The complete usage example is as follows: -```python hl_lines="6" +```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import ScreenGear import cv2 @@ -150,7 +150,7 @@ ScreenGear API provides us the flexibility to select any connected display for f ??? tip "Using GPU acceleration on Windows :fontawesome-brands-windows:" With `dxcam` library backend, you can also assign which GPU devices ids to use along with monitor device ids as tuple `(monitor_idx, gpu_idx)`, as follows: - ```python + ```python linenums="1" # open video stream with defined parameters with # monitor at index `1` and GPU at index `0`. stream = ScreenGear(monitor=(1,0), logging=True).start() @@ -167,7 +167,7 @@ ScreenGear API provides us the flexibility to select any connected display for f 'Device[0] Output[0]: Res:(1920, 1080) Rot:0 Primary:True\nDevice[0] Output[1]: Res:(1920, 1080) Rot:0 Primary:False\n' ``` - ```python hl_lines="6" + ```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import ScreenGear import cv2 @@ -209,7 +209,7 @@ ScreenGear API provides us the flexibility to select any connected display for f !!! danger "With `mss` library backend, API will output [`BGRA`](https://en.wikipedia.org/wiki/RGBA_color_model) colorspace frames instead of default `BGR`." - ```python hl_lines="6" + ```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import ScreenGear import cv2 @@ -260,7 +260,7 @@ With ScreenGear API, you can select from many different backends that generates !!! failure "Any value on `monitor` parameter will disable the `backend` parameter. You cannot use them simultaneously." -```python hl_lines="7" +```python linenums="1" hl_lines="7" # import required libraries from vidgear.gears import ScreenGear import cv2 @@ -310,7 +310,7 @@ In following example code, we will start with [**HSV**](https://en.wikipedia.org !!! warning "Any incorrect or None-type value, will immediately revert the colorspace to default i.e. `BGR`." -```python hl_lines="6 29 33 37" +```python linenums="1" hl_lines="6 29 33 37" # import required libraries from vidgear.gears import ScreenGear import cv2 @@ -367,7 +367,7 @@ stream.stop() ScreenGear can be used in conjunction with WriteGear API directly without any compatibility issues. The suitable example is as follows: -```python +```python linenums="1" # import required libraries from vidgear.gears import ScreenGear from vidgear.gears import WriteGear diff --git a/docs/gears/stabilizer/usage.md b/docs/gears/stabilizer/usage.md index d31f5fff4..a508b0453 100644 --- a/docs/gears/stabilizer/usage.md +++ b/docs/gears/stabilizer/usage.md @@ -41,7 +41,7 @@ Following is the bare-minimum code you need to get started with Stabilizer Class !!! tip "You can use any VideoCapture Gear instead of CamGear in the similar manner, as shown in this usage example." -```python +```python linenums="1" # import required libraries from vidgear.gears.stabilizer import Stabilizer from vidgear.gears import CamGear @@ -96,7 +96,7 @@ stream.stop() The VidGear's stabilizer class can also work standalone easily with any Computer Vision library such as OpenCV itself. Following is the bare-minimum code you need to get started with Stabilizer Class and OpenCV: -```python +```python linenums="1" # import required libraries from vidgear.gears.stabilizer import Stabilizer import cv2 @@ -150,7 +150,7 @@ stream.release() Stabilizer class provide certain [parameters](../params/) which you can use to tweak its internal properties. The complete usage example is as follows: -```python hl_lines="10" +```python linenums="1" hl_lines="10" # import required libraries from vidgear.gears.stabilizer import Stabilizer from vidgear.gears import CamGear @@ -208,7 +208,7 @@ VideoGear's stabilizer can be used in conjunction with WriteGear API directly wi !!! example "You can also add live audio input to WriteGear pipeline. See this [bonus example ➶](../../../help)" -```python +```python linenums="1" # import required libraries from vidgear.gears.stabilizer import Stabilizer from vidgear.gears import CamGear diff --git a/docs/gears/streamgear/rtfm/usage.md b/docs/gears/streamgear/rtfm/usage.md index 9ac0a9605..be8a38e23 100644 --- a/docs/gears/streamgear/rtfm/usage.md +++ b/docs/gears/streamgear/rtfm/usage.md @@ -50,7 +50,7 @@ Following is the bare-minimum code you need to get started with StreamGear API i === "DASH" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -99,7 +99,7 @@ Following is the bare-minimum code you need to get started with StreamGear API i === "HLS" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -164,7 +164,7 @@ You can easily activate ==Low-latency Livestreaming in Real-time Frames Mode==, !!! alert "After every few chunks _(equal to the sum of `-window_size` & `-extra_window_size` values)_, all chunks will be overwritten in Live-Streaming. Thereby, since newer chunks in manifest will contain NO information of any older ones, and therefore resultant DASH stream will play only the most recent frames." - ```python hl_lines="11" + ```python linenums="1" hl_lines="11" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -221,7 +221,7 @@ You can easily activate ==Low-latency Livestreaming in Real-time Frames Mode==, !!! alert "After every few chunks _(equal to the sum of `-hls_init_time` & `-hls_time` values)_, all chunks will be overwritten in Live-Streaming. Thereby, since newer chunks in playlist will contain NO information of any older ones, and therefore resultant HLS stream will play only the most recent frames." - ```python hl_lines="11" + ```python linenums="1" hl_lines="11" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -281,7 +281,7 @@ The complete usage example is as follows: === "DASH" - ```python hl_lines="28" + ```python linenums="1" hl_lines="28" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -331,7 +331,7 @@ The complete usage example is as follows: === "HLS" - ```python hl_lines="28" + ```python linenums="1" hl_lines="28" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -393,7 +393,7 @@ In this example, we will retrieve framerate from webcam video-stream, and set it === "DASH" - ```python hl_lines="10" + ```python linenums="1" hl_lines="10" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -445,7 +445,7 @@ In this example, we will retrieve framerate from webcam video-stream, and set it === "HLS" - ```python hl_lines="10" + ```python linenums="1" hl_lines="10" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -507,7 +507,7 @@ The complete usage example is as follows: === "DASH" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import StreamGear import cv2 @@ -556,7 +556,7 @@ The complete usage example is as follows: === "HLS" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import StreamGear import cv2 @@ -626,7 +626,7 @@ The complete example is as follows: === "DASH" - ```python hl_lines="11-15" + ```python linenums="1" hl_lines="11-15" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -684,7 +684,7 @@ The complete example is as follows: === "HLS" - ```python hl_lines="11-15" + ```python linenums="1" hl_lines="11-15" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -757,7 +757,7 @@ The complete example is as follows: === "DASH" - ```python hl_lines="16-17" + ```python linenums="1" hl_lines="16-17" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -817,7 +817,7 @@ The complete example is as follows: === "HLS" - ```python hl_lines="16-17" + ```python linenums="1" hl_lines="16-17" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -922,7 +922,7 @@ The complete example is as follows: - [x] **Specify Sound Card:** Then, you can specify your located soundcard in StreamGear as follows: - ```python + ```python linenums="1" # assign appropriate input audio-source device and demuxer device and demuxer stream_params = {"-audio": ["-f","dshow", "-i", "audio=Microphone (USB2.0 Camera)"]} ``` @@ -962,7 +962,7 @@ The complete example is as follows: !!! info "The easiest thing to do is to reference sound card directly, namely "card 0" (Intel ICH5) and "card 1" (Microphone on the USB web cam), as `hw:0` or `hw:1`" - ```python + ```python linenums="1" # assign appropriate input audio-source device and demuxer device and demuxer stream_params = {"-audio": ["-f","alsa", "-i", "hw:1"]} ``` @@ -998,7 +998,7 @@ The complete example is as follows: - [x] **Specify Sound Card:** Then, you can specify your located soundcard in StreamGear as follows: - ```python + ```python linenums="1" # assign appropriate input audio-source device and demuxer stream_params = {"-audio": ["-f","avfoundation", "-audio_device_index", "0"]} ``` @@ -1015,7 +1015,7 @@ The complete example is as follows: === "DASH" - ```python hl_lines="18-24" + ```python linenums="1" hl_lines="18-24" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -1080,7 +1080,7 @@ The complete example is as follows: === "HLS" - ```python hl_lines="18-24" + ```python linenums="1" hl_lines="18-24" # import required libraries from vidgear.gears import CamGear from vidgear.gears import StreamGear @@ -1171,7 +1171,7 @@ In this example, we will be using `h264_vaapi` as our hardware encoder and also === "DASH" - ```python hl_lines="16-18" + ```python linenums="1" hl_lines="16-18" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import StreamGear @@ -1232,7 +1232,7 @@ In this example, we will be using `h264_vaapi` as our hardware encoder and also === "HLS" - ```python hl_lines="16-18" + ```python linenums="1" hl_lines="16-18" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import StreamGear diff --git a/docs/gears/streamgear/ssm/usage.md b/docs/gears/streamgear/ssm/usage.md index 1b6958d7f..6a83d82ff 100644 --- a/docs/gears/streamgear/ssm/usage.md +++ b/docs/gears/streamgear/ssm/usage.md @@ -44,7 +44,7 @@ Following is the bare-minimum code you need to get started with StreamGear API i === "DASH" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import StreamGear @@ -60,7 +60,7 @@ Following is the bare-minimum code you need to get started with StreamGear API i === "HLS" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import StreamGear @@ -92,7 +92,7 @@ You can easily activate ==Low-latency Livestreaming in Single-Source Mode== - ch !!! alert "After every few chunks _(equal to the sum of `-window_size` & `-extra_window_size` values)_, all chunks will be overwritten in Live-Streaming. Thereby, since newer chunks in manifest will contain NO information of any older ones, and therefore resultant DASH stream will play only the most recent frames." - ```python hl_lines="5" + ```python linenums="1" hl_lines="5" # import required libraries from vidgear.gears import StreamGear @@ -114,7 +114,7 @@ You can easily activate ==Low-latency Livestreaming in Single-Source Mode== - ch !!! alert "After every few chunks _(equal to the sum of `-hls_init_time` & `-hls_time` values)_, all chunks will be overwritten in Live-Streaming. Thereby, since newer chunks in playlist will contain NO information of any older ones, and therefore resultant HLS stream will play only the most recent frames." - ```python hl_lines="5" + ```python linenums="1" hl_lines="5" # import required libraries from vidgear.gears import StreamGear @@ -153,7 +153,7 @@ The complete example is as follows: === "DASH" - ```python hl_lines="6-12" + ```python linenums="1" hl_lines="6-12" # import required libraries from vidgear.gears import StreamGear @@ -177,7 +177,7 @@ The complete example is as follows: === "HLS" - ```python hl_lines="6-12" + ```python linenums="1" hl_lines="6-12" # import required libraries from vidgear.gears import StreamGear @@ -214,7 +214,7 @@ The complete example is as follows: === "DASH" - ```python hl_lines="12" + ```python linenums="1" hl_lines="12" # import required libraries from vidgear.gears import StreamGear @@ -238,7 +238,7 @@ The complete example is as follows: === "HLS" - ```python hl_lines="12" + ```python linenums="1" hl_lines="12" # import required libraries from vidgear.gears import StreamGear @@ -279,7 +279,7 @@ For this example, let us use our own [H.265/HEVC](https://trac.ffmpeg.org/wiki/E === "DASH" - ```python hl_lines="6-10 15-17" + ```python linenums="1" hl_lines="6-10 15-17" # import required libraries from vidgear.gears import StreamGear @@ -309,7 +309,7 @@ For this example, let us use our own [H.265/HEVC](https://trac.ffmpeg.org/wiki/E === "HLS" - ```python hl_lines="6-10 15-17" + ```python linenums="1" hl_lines="6-10 15-17" # import required libraries from vidgear.gears import StreamGear diff --git a/docs/gears/videogear/usage.md b/docs/gears/videogear/usage.md index 06dec9429..3ef8bcb32 100644 --- a/docs/gears/videogear/usage.md +++ b/docs/gears/videogear/usage.md @@ -31,7 +31,7 @@ limitations under the License. Following is the bare-minimum code you need to access CamGear API with VideoGear: -```python +```python linenums="1" # import required libraries from vidgear.gears import VideoGear import cv2 @@ -86,7 +86,7 @@ Following is the bare-minimum code you need to access PiGear API with VideoGear: !!! warning "Make sure to [complete Raspberry Pi Camera Hardware-specific settings](https://www.raspberrypi.com/documentation/accessories/camera.html#installing-a-raspberry-pi-camera) prior using this API, otherwise nothing will work." -```python hl_lines="6" +```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import VideoGear import cv2 @@ -133,7 +133,7 @@ The usage example is as follows: !!! warning "The stabilizer might be slower for High-Quality/Resolution videos-frames." -```python hl_lines="7" +```python linenums="1" hl_lines="7" # import required libraries from vidgear.gears import VideoGear import numpy as np @@ -181,7 +181,7 @@ The usage example of VideoGear API with Variable Camera Properties is as follows !!! tip "All the supported Source Tweak Parameters can be found [here ➶](../../camgear/advanced/source_params/#source-tweak-parameters-for-camgear-api)" -```python hl_lines="15" +```python linenums="1" hl_lines="15" # import required libraries from vidgear.gears import VideoGear import cv2 @@ -242,7 +242,7 @@ The usage example of VideoGear API with Variable Camera Properties is as follows === "New Picamera2 backend" - ```python hl_lines="3 9-13" + ```python linenums="1" hl_lines="3 9-13" # import required libraries from vidgear.gears import VideoGear from libcamera import Transform @@ -298,7 +298,7 @@ The usage example of VideoGear API with Variable Camera Properties is as follows !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../params) user-defined optional parameter boolean attribute." - ```python hl_lines="8-13" + ```python linenums="1" hl_lines="8-13" # import required libraries from vidgear.gears import VideoGear import cv2 @@ -360,7 +360,7 @@ VideoGear API also supports **Colorspace Manipulation** but **NOT Direct** like In following example code, we will convert source colorspace to [**HSV**](https://en.wikipedia.org/wiki/HSL_and_HSV) on initialization: -```python hl_lines="6" +```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import VideoGear import cv2 diff --git a/docs/gears/webgear/advanced.md b/docs/gears/webgear/advanced.md index b8a0fdbf7..35105f53a 100644 --- a/docs/gears/webgear/advanced.md +++ b/docs/gears/webgear/advanced.md @@ -41,7 +41,7 @@ Let's implement a bare-minimum example using WebGear, where we will be sending [ !!! info "Supported `jpeg_compression_colorspace` colorspace values are `RGB`, `BGR`, `RGBX`, `BGRX`, `XBGR`, `XRGB`, `GRAY`, `RGBA`, `BGRA`, `ABGR`, `ARGB`, `CMYK`. More information can be found [here ➶](https://gitlab.com/jfolz/simplejpeg)" -```python hl_lines="8" +```python linenums="1" hl_lines="8" # import required libraries import uvicorn from vidgear.gears.asyncio import WebGear @@ -83,7 +83,7 @@ WebGear allows you to easily define your own custom Source that you want to use Let's implement a bare-minimum example with a Custom Source using WebGear API and OpenCV: -```python hl_lines="10-34 38" +```python linenums="1" hl_lines="10-34 38" # import necessary libs import uvicorn, asyncio, cv2 from vidgear.gears.asyncio import WebGear @@ -139,7 +139,7 @@ web.shutdown() With our highly extensible WebGear API, you can add your own mounting points, where additional files located, as follows: -```python hl_lines="21-23" +```python linenums="1" hl_lines="21-23" # import libs import uvicorn from starlette.routing import Mount @@ -200,7 +200,7 @@ Suppose we want to add a simple **`hello world` webpage** to our WebGear server. Then in our application code, we can integrate this webpage route, as follows: -```python hl_lines="11-14 31" +```python linenums="1" hl_lines="11-14 31" # import libs import uvicorn, asyncio from starlette.templating import Jinja2Templates @@ -258,7 +258,7 @@ For this example, let's use [`CORSMiddleware`](https://www.starlette.io/middlewa !!! tip "Starlette provides several arguments for enabling origins, methods, or headers for CORSMiddleware API. More information can be found [here ➶](https://www.starlette.io/middleware/#corsmiddleware)" -```python hl_lines="21-29" +```python linenums="1" hl_lines="21-29" # import libs import uvicorn, asyncio from starlette.middleware import Middleware diff --git a/docs/gears/webgear/usage.md b/docs/gears/webgear/usage.md index 7673f739b..cb7267e25 100644 --- a/docs/gears/webgear/usage.md +++ b/docs/gears/webgear/usage.md @@ -91,7 +91,7 @@ You can access and run WebGear VideoStreamer Server programmatically in your pyt !!! tip "For accessing WebGear on different Client Devices on the network, use `"0.0.0.0"` as host value instead of `"localhost"` on Host Machine. More information can be found [here ➶](../../../help/webgear_faqs/#is-it-possible-to-stream-on-a-different-device-on-the-network-with-webgear)" -```python hl_lines="7-10" +```python linenums="1" hl_lines="7-10" # import required libraries import uvicorn from vidgear.gears.asyncio import WebGear diff --git a/docs/gears/webgear_rtc/advanced.md b/docs/gears/webgear_rtc/advanced.md index 28bdbbbc4..08b313105 100644 --- a/docs/gears/webgear_rtc/advanced.md +++ b/docs/gears/webgear_rtc/advanced.md @@ -38,7 +38,7 @@ Let's implement a bare-minimum example using WebGear_RTC as Real-time Broadcaste !!! tip "For accessing WebGear_RTC on different Client Devices on the network, we use `"0.0.0.0"` as host value instead of `"localhost"` on Host Machine. More information can be found [here ➶](../../../help/webgear_rtc_faqs/#is-it-possible-to-stream-on-a-different-device-on-the-network-with-webgear_rtc)" -```python hl_lines="8" +```python linenums="1" hl_lines="8" # import required libraries import uvicorn from vidgear.gears.asyncio import WebGear_RTC @@ -83,7 +83,7 @@ Let's implement a bare-minimum example with a Custom Source using WebGear_RTC AP See this [example ➶](../../../help/screengear_ex/#using-screengear-with-webgear_rtc) for more information. -```python hl_lines="6-54 58" +```python linenums="1" hl_lines="6-54 58" # import necessary libs import uvicorn, cv2 from vidgear.gears.asyncio import WebGear_RTC @@ -163,7 +163,7 @@ web.shutdown() With our highly extensible WebGear_RTC API, you can add your own mounting points, where additional files located, as follows: -```python hl_lines="18-20" +```python linenums="1" hl_lines="18-20" # import libs import uvicorn from starlette.routing import Mount @@ -221,7 +221,7 @@ Suppose we want to add a simple **`hello world` webpage** to our WebGear_RTC ser Then in our application code, we can integrate this webpage route, as follows: -```python hl_lines="11-14 28" +```python linenums="1" hl_lines="11-14 28" # import libs import uvicorn, asyncio from starlette.templating import Jinja2Templates @@ -276,7 +276,7 @@ For this example, let's use [`CORSMiddleware`](https://www.starlette.io/middlewa !!! tip "Starlette provides several arguments for enabling origins, methods, or headers for CORSMiddleware API. More information can be found [here ➶](https://www.starlette.io/middleware/#corsmiddleware)" -```python hl_lines="18-26" +```python linenums="1" hl_lines="18-26" # import libs import uvicorn, asyncio from starlette.middleware import Middleware diff --git a/docs/gears/webgear_rtc/usage.md b/docs/gears/webgear_rtc/usage.md index 5301ba840..6a7d1a147 100644 --- a/docs/gears/webgear_rtc/usage.md +++ b/docs/gears/webgear_rtc/usage.md @@ -76,7 +76,7 @@ You can access and run WebGear_RTC VideoStreamer Server programmatically in your !!! info "We are using `frame_size_reduction` attribute for frame size reduction _(in percentage)_ to be streamed with its [`options`](../params/#options) dictionary parameter to cope with performance-throttling in this example." -```python hl_lines="7" +```python linenums="1" hl_lines="7" # import required libraries import uvicorn from vidgear.gears.asyncio import WebGear_RTC diff --git a/docs/gears/writegear/compression/advanced/cciw.md b/docs/gears/writegear/compression/advanced/cciw.md index 9580e43da..88694495a 100644 --- a/docs/gears/writegear/compression/advanced/cciw.md +++ b/docs/gears/writegear/compression/advanced/cciw.md @@ -82,7 +82,7 @@ execute_ffmpeg_cmd(ffmpeg_command) In this example, we will extract and save audio from a URL stream: -```python hl_lines="13-18 21" +```python linenums="1" hl_lines="13-18 21" # import required libraries from vidgear.gears import WriteGear @@ -126,7 +126,7 @@ In this example, we will merge audio with video: * Both these Audio and Video files are compatible. -```python hl_lines="59-75 78" +```python linenums="1" hl_lines="59-75 78" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import WriteGear diff --git a/docs/gears/writegear/compression/usage.md b/docs/gears/writegear/compression/usage.md index 9ac7e48a1..4f12add16 100644 --- a/docs/gears/writegear/compression/usage.md +++ b/docs/gears/writegear/compression/usage.md @@ -47,7 +47,7 @@ limitations under the License. Following is the bare-minimum code you need to get started with WriteGear API in Compression Mode: -```python +```python linenums="1" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -100,7 +100,7 @@ In Compression Mode, WriteGear API contains [`rgb_mode`](../../../../bonus/refer The complete usage example is as follows: -```python hl_lines="26" +```python linenums="1" hl_lines="26" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import WriteGear @@ -168,7 +168,7 @@ WriteGear API provides [`-input_framerate`](../params/#supported-parameters) at In this code we will retrieve framerate from video stream, and set it as `-input_framerate` attribute for `option` parameter in WriteGear API: -```python hl_lines="10" +```python linenums="1" hl_lines="10" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -233,7 +233,7 @@ In this example, we will stream live camera frames directly to Twitch :fontaweso !!! alert "Make sure to change [_Twitch Stream Key_](https://www.youtube.com/watch?v=xwOtOfPMIIk) with yours in following code before running!" -```python hl_lines="11-16 20 24" +```python linenums="1" hl_lines="11-16 20 24" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -324,7 +324,7 @@ In this example, we will be using `h264_vaapi` as our hardware encoder and also ``` -```python hl_lines="11-13" +```python linenums="1" hl_lines="11-13" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -382,7 +382,7 @@ writer.close() You can easily use WriterGear API directly with any Video Processing library(_For e.g OpenCV itself_) in Compression Mode. The complete usage example is as follows: -```python hl_lines="6" +```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import WriteGear import cv2 @@ -584,7 +584,7 @@ In this example code, we will merging the audio from a Audio Device _(for e.g. W !!! warning "You **MUST** use [`-input_framerate`](../params/#supported-parameters) attribute to set exact value of input framerate when using external audio in Real-time Frames mode, otherwise audio delay will occur in output streams." -```python hl_lines="11-15" +```python linenums="1" hl_lines="11-15" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import WriteGear diff --git a/docs/gears/writegear/non_compression/usage.md b/docs/gears/writegear/non_compression/usage.md index 71c4c5dce..1ec44f83a 100644 --- a/docs/gears/writegear/non_compression/usage.md +++ b/docs/gears/writegear/non_compression/usage.md @@ -40,7 +40,7 @@ limitations under the License. Following is the bare-minimum code you need to get started with WriteGear API in Non-Compression Mode: -```python +```python linenums="1" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -97,7 +97,7 @@ In Non-Compression mode, WriteGear API provides flexible control over [**OpenCV' The complete usage example is as follows: -```python +```python linenums="1" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import WriteGear @@ -159,7 +159,7 @@ writer.close() You can easily use WriterGear API directly with any Video Processing library(_For e.g OpenCV itself_) in Non-Compression Mode. The complete usage example is as follows: -```python +```python linenums="1" # import required libraries from vidgear.gears import WriteGear import cv2 @@ -227,7 +227,7 @@ writer.close() In this example we will be constructing GStreamer pipeline to write video-frames into a file(`foo.mp4`) at 1M video-bitrate. -```python +```python linenums="1" # import required libraries from vidgear.gears import WriteGear import cv2 diff --git a/docs/help.md b/docs/help.md index 57bc9b136..61618c220 100644 --- a/docs/help.md +++ b/docs/help.md @@ -67,7 +67,7 @@ You can try helping solving those issues, or give valuable feedback/review on ne It is something I am doing with my own free time. But so much more needs to be done, and I need your help to do this. For just the price of a cup of coffee, you can make a difference :slight_smile: - +Buy Me a Coffee at ko-fi.com Thanks a million! :blush: diff --git a/docs/help/camgear_ex.md b/docs/help/camgear_ex.md index af72f74d2..096653388 100644 --- a/docs/help/camgear_ex.md +++ b/docs/help/camgear_ex.md @@ -28,7 +28,7 @@ In this example both streams and corresponding frames will be processed synchron !!! danger "Using same source with more than one instances of CamGear can lead to [Global Interpreter Lock (GIL)](https://wiki.python.org/moin/GlobalInterpreterLock#:~:text=In%20CPython%2C%20the%20global%20interpreter,conditions%20and%20ensures%20thread%20safety.&text=The%20GIL%20can%20degrade%20performance%20even%20when%20it%20is%20not%20a%20bottleneck.) that degrades performance even when it is not a bottleneck." -```python +```python linenums="1" # import required libraries from vidgear.gears import CamGear import cv2 @@ -89,7 +89,7 @@ The complete usage example is as follows: !!! tip "More information on `STREAM_RESOLUTION` & `STREAM_PARAMS` attributes can be found [here ➶](../../gears/camgear/advanced/source_params/#exclusive-camgear-parameters)" -```python hl_lines="6" +```python linenums="1" hl_lines="6" # import required libraries from vidgear.gears import CamGear import cv2 @@ -147,7 +147,7 @@ Here's a high-level wrapper code around CamGear API to enable auto-reconnection You can easily enforce UDP for RTSP streams inplace of default TCP, by putting following lines of code on the top of your existing code: - ```python + ```python # import required libraries import os @@ -158,7 +158,7 @@ Here's a high-level wrapper code around CamGear API to enable auto-reconnection Finally, use [`backend`](../../gears/camgear/params/#backend) parameter value as `backend=cv2.CAP_FFMPEG` in CamGear. -```python +```python linenums="1" from vidgear.gears import CamGear import cv2 import datetime diff --git a/docs/help/netgear_async_ex.md b/docs/help/netgear_async_ex.md index 3e9ca26b2..1b7110e2c 100644 --- a/docs/help/netgear_async_ex.md +++ b/docs/help/netgear_async_ex.md @@ -41,7 +41,7 @@ Open a terminal on Client System where you want to display the input frames _(an !!! note "Note down the IP-address of this system _(required at Server's end)_ by executing the `hostname -I` command and also replace it in the following code."" -```python +```python linenums="1" hl_lines="16-32 40 43 46" # import libraries from vidgear.gears.asyncio import NetGear_Async from vidgear.gears.asyncio import WebGear @@ -104,7 +104,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! note "Replace the IP address in the following code with Client's IP address you noted earlier." -```python +```python linenums="1" # import library from vidgear.gears.asyncio import NetGear_Async import cv2, asyncio diff --git a/docs/help/netgear_ex.md b/docs/help/netgear_ex.md index 32cbaad3f..375198689 100644 --- a/docs/help/netgear_ex.md +++ b/docs/help/netgear_ex.md @@ -41,7 +41,7 @@ Open a terminal on Client System where you want to display the input frames _(an !!! info "Note down the local IP-address of this system (required at Server's end) and also replace it in the following code. You can follow [this FAQ](../netgear_faqs/#how-to-find-local-ip-address-on-different-os-platforms) for this purpose." -```python +```python linenums="1" # import necessary libs import uvicorn, asyncio, cv2 from vidgear.gears import NetGear @@ -119,7 +119,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! note "Replace the IP address in the following code with Client's IP address you noted earlier." -```python +```python linenums="1" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear @@ -196,7 +196,7 @@ Open a terminal on Client System where you want to display the input frames _(an !!! failure "For VideoCapture APIs you also need to implement `start()` in addition to `read()` and `stop()` methods in your Custom Streaming Class as shown in following example, otherwise WebGear_RTC will fail to work!" -```python hl_lines="8-79 92-101" +```python linenums="1" hl_lines="8-79 92-101" # import necessary libs import uvicorn, cv2 from vidgear.gears import NetGear @@ -317,7 +317,7 @@ Now, Open the terminal on another Server System _(with a webcam connected to it !!! note "Replace the IP address in the following code with Client's IP address you noted earlier." -```python +```python linenums="1" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import NetGear diff --git a/docs/help/pigear_ex.md b/docs/help/pigear_ex.md index f69257f4c..74e6ac5ea 100644 --- a/docs/help/pigear_ex.md +++ b/docs/help/pigear_ex.md @@ -47,7 +47,7 @@ limitations under the License. !!! tip "You could also instead define [`colorspace="COLOR_YUV420p2RGB"`](../params/#colorspace) parameter in PiGear API for converting it back to `BGR` similarly." - ```python hl_lines="8 27" + ```python linenums="1" hl_lines="8 27" # import required libraries from vidgear.gears import PiGear import cv2 @@ -103,7 +103,7 @@ limitations under the License. !!! tip "You could also instead define [`colorspace="COLOR_YUV2BGR_YUYV"`](../params/#colorspace) parameter in PiGear API for converting it back to `BGR` similarly." - ```python hl_lines="8 27" + ```python linenums="1" hl_lines="8 27" # import required libraries from vidgear.gears import PiGear import cv2 @@ -208,7 +208,7 @@ limitations under the License. stream.stop() ``` - ```python hl_lines="7 37" + ```python linenums="1" hl_lines="7 37" # import required libraries from vidgear.gears import PiGear import cv2 @@ -266,7 +266,7 @@ limitations under the License. In this example we will set initial Camera Module's `brightness` value `80` _(brighter)_, and will change it `30` _(darker)_ when ++"Z"++ key is pressed at runtime: - ```python hl_lines="7 37" + ```python linenums="1" hl_lines="7 37" # import required libraries from vidgear.gears import PiGear import cv2 @@ -352,7 +352,7 @@ limitations under the License. !!! alert "This example assumes a Camera Module is connected at index `1`, and some other camera connected at index `0` on your Raspberry Pi." - ```python hl_lines="19" + ```python linenums="1" hl_lines="19" # import required libraries from vidgear.gears import PiGear from libcamera import Transform @@ -413,7 +413,7 @@ limitations under the License. !!! alert "This example assumes a Camera Module is connected at index `1` on your Raspberry Pi." - ```python hl_lines="17" + ```python linenums="1" hl_lines="17" # import required libraries from vidgear.gears import PiGear import cv2 diff --git a/docs/help/screengear_ex.md b/docs/help/screengear_ex.md index 8c297252a..6623e6dae 100644 --- a/docs/help/screengear_ex.md +++ b/docs/help/screengear_ex.md @@ -37,7 +37,7 @@ Open a terminal on Client System _(where you want to save the input frames recei !!! tip "You can terminate client anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import NetGear from vidgear.gears import WriteGear @@ -94,7 +94,7 @@ Now, Open the terminal on another Server System _(with a montior/display attache !!! tip "You can terminate stream on both side anytime by pressing ++ctrl+"C"++ on your keyboard!" -```python +```python linenums="1" # import required libraries from vidgear.gears import ScreenGear from vidgear.gears import NetGear @@ -156,7 +156,7 @@ The complete usage example is as follows: === "Bare-Minimum" - ```python hl_lines="8" + ```python linenums="1" hl_lines="8" # import necessary libs import uvicorn, cv2 from vidgear.gears import ScreenGear @@ -180,7 +180,7 @@ The complete usage example is as follows: !!! failure "For VideoCapture APIs you also need to implement `start()` in addition to `read()` and `stop()` methods in your Custom Streaming Class as shown in following example, otherwise WebGear_RTC will fail to work!" - ```python hl_lines="8-64 69" + ```python linenums="1" hl_lines="8-64 69" # import necessary libs import uvicorn, cv2 from vidgear.gears import ScreenGear diff --git a/docs/help/stabilizer_ex.md b/docs/help/stabilizer_ex.md index 36f050946..3d0154214 100644 --- a/docs/help/stabilizer_ex.md +++ b/docs/help/stabilizer_ex.md @@ -37,7 +37,7 @@ In this example code, we will merging the audio from a Audio Device _(for e.g. W ??? tip "Identifying and Specifying sound card on different OS platforms" - === "On Windows" + === "Windows :fontawesome-brands-windows:" Windows OS users can use the [dshow](https://trac.ffmpeg.org/wiki/DirectShow) (DirectShow) to list audio input device which is the preferred option for Windows users. You can refer following steps to identify and specify your sound card: @@ -82,7 +82,7 @@ In this example code, we will merging the audio from a Audio Device _(for e.g. W !!! failure "If audio still doesn't work then [checkout this troubleshooting guide ➶](https://www.maketecheasier.com/fix-microphone-not-working-windows10/) or reach us out on [Gitter ➶](https://gitter.im/vidgear/community) Community channel" - === "On Linux" + === "Linux :material-linux:" Linux OS users can use the [alsa](https://ffmpeg.org/ffmpeg-all.html#alsa) to list input device to capture live audio input such as from a webcam. You can refer following steps to identify and specify your sound card: @@ -128,7 +128,7 @@ In this example code, we will merging the audio from a Audio Device _(for e.g. W !!! failure "If audio still doesn't work then reach us out on [Gitter ➶](https://gitter.im/vidgear/community) Community channel" - === "On MacOS" + === "MacOS :material-apple:" MAC OS users can use the [avfoundation](https://ffmpeg.org/ffmpeg-devices.html#avfoundation) to list input devices for grabbing audio from integrated iSight cameras as well as cameras connected via USB or FireWire. You can refer following steps to identify and specify your sound card on MacOS/OSX machines: @@ -174,7 +174,7 @@ In this example code, we will merging the audio from a Audio Device _(for e.g. W !!! warning "You **MUST** use [`-input_framerate`](../../gears/writegear/compression/params/#supported-parameters) attribute to set exact value of input framerate when using external audio in Real-time Frames mode, otherwise audio delay will occur in output streams." -```python +```python linenums="1" hl_lines="14-19" # import required libraries from vidgear.gears import WriteGear from vidgear.gears.stabilizer import Stabilizer @@ -192,7 +192,7 @@ output_params = { "-thread_queue_size": "512", "-ac": "2", "-ar": "48000", - "-f": "alsa", # !!! warning: always keep this line above "-i" parameter !!! + "-f": "alsa", # (1) "-i": "hw:1", } @@ -232,6 +232,8 @@ stream.release() writer.close() ``` +1. :warning: Always keep this line above `-i` parameter! +   ## Saving Stabilizer Class output with File Audio Input @@ -247,7 +249,7 @@ In this example code, we will be directly merging the audio from a Video-File _( !!! alert "Use [`-disable_force_termination`](../../gears/writegear/compression/params/#supported-parameters) flag when video duration is too short(<60sec), otherwise WriteGear will not produce any valid output." -```python +```python linenums="1" hl_lines="17-22 49" # import required libraries from vidgear.gears import WriteGear from vidgear.gears.stabilizer import Stabilizer diff --git a/docs/help/streamgear_ex.md b/docs/help/streamgear_ex.md index 01ea7b971..e1fc6a81e 100644 --- a/docs/help/streamgear_ex.md +++ b/docs/help/streamgear_ex.md @@ -40,7 +40,7 @@ In this example, we will be Live-Streaming video-frames from Raspberry Pi _(with === "New Picamera2 backend" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import PiGear from vidgear.gears import StreamGear @@ -110,7 +110,7 @@ In this example, we will be Live-Streaming video-frames from Raspberry Pi _(with !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../params) user-defined optional parameter boolean attribute." - ```python + ```python linenums="1" # import required libraries from vidgear.gears import PiGear from vidgear.gears import StreamGear @@ -174,7 +174,7 @@ In this example, we will be Live-Streaming video-frames from Raspberry Pi _(with === "New Picamera2 backend" - ```python + ```python linenums="1" # import required libraries from vidgear.gears import PiGear from vidgear.gears import StreamGear @@ -244,7 +244,7 @@ In this example, we will be Live-Streaming video-frames from Raspberry Pi _(with !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../params) user-defined optional parameter boolean attribute." - ```python + ```python linenums="1" # import required libraries from vidgear.gears import PiGear from vidgear.gears import StreamGear diff --git a/docs/help/videogear_ex.md b/docs/help/videogear_ex.md index e2a5b7f3f..cc70ffc32 100644 --- a/docs/help/videogear_ex.md +++ b/docs/help/videogear_ex.md @@ -33,7 +33,7 @@ In this example, we'll create a node that convert OpenCV frames into ROS image m !!! note "This example is vidgear implementation of this [wiki example](http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython)." -```python +```python linenums="1" # import roslib import roslib @@ -130,7 +130,7 @@ Here's a high-level wrapper code around VideoGear API to enable auto-reconnectio Finally, use [`backend`](../../gears/videogear/params/#backend) parameter value as `backend=cv2.CAP_FFMPEG` in VideoGear. -```python +```python linenums="1" from vidgear.gears import VideoGear import cv2 import datetime @@ -233,7 +233,7 @@ In this example code, we will be directly merging the audio from a Video-File _( !!! alert "Use `-disable_force_termination` flag when video duration is too short(<60sec), otherwise WriteGear will not produce any valid output." -```python +```python linenums="1" # import required libraries from vidgear.gears import WriteGear from vidgear.gears import VideoGear diff --git a/docs/help/webgear_ex.md b/docs/help/webgear_ex.md index f3a9a4390..232af93bb 100644 --- a/docs/help/webgear_ex.md +++ b/docs/help/webgear_ex.md @@ -37,7 +37,7 @@ Here's a bare-minimum example of using WebGear API with the Raspberry Pi camera === "New Picamera2 backend" - ```python + ```python linenums="1" hl_lines="22" # import libs import uvicorn from libcamera import Transform @@ -79,7 +79,7 @@ Here's a bare-minimum example of using WebGear API with the Raspberry Pi camera !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." - ```python + ```python linenums="1" hl_lines="21" # import libs import uvicorn from vidgear.gears.asyncio import WebGear @@ -116,7 +116,7 @@ Here's a bare-minimum example of using WebGear API with the Raspberry Pi camera Here's an example of using WebGear API with real-time Video Stabilization enabled: -```python +```python linenums="1" hl_lines="14" # import libs import uvicorn from vidgear.gears.asyncio import WebGear @@ -151,7 +151,7 @@ In this example, we'll be displaying two video feeds side-by-side simultaneously **Step-1 (Trigger Auto-Generation Process):** Firstly, run this bare-minimum code to trigger the [**Auto-generation**](../../gears/webgear/overview/#auto-generation-process) process, this will create `.vidgear` directory at current location _(directory where you'll run this code)_: -```python +```python linenums="1" hl_lines="6" # import required libraries import uvicorn from vidgear.gears.asyncio import WebGear @@ -168,7 +168,7 @@ web.shutdown() **Step-2 (Replace HTML file):** Now, go inside `.vidgear` :arrow_right: `webgear` :arrow_right: `templates` directory at current location of your machine, and there replace content of `index.html` file with following: -```html +```html hl_lines="5-6" {% extends "base.html" %} {% block content %}

WebGear Video Feed

@@ -181,7 +181,7 @@ web.shutdown() **Step-3 (Build your own Frame Producers):** Now, create a python script code with OpenCV source, as follows: -```python +```python linenums="1" hl_lines="9 15-38 42-65 68-77 81 84-86" # import necessary libs import uvicorn, asyncio, cv2 from vidgear.gears.asyncio import WebGear diff --git a/docs/help/webgear_rtc_ex.md b/docs/help/webgear_rtc_ex.md index f795b892c..55f1bb78e 100644 --- a/docs/help/webgear_rtc_ex.md +++ b/docs/help/webgear_rtc_ex.md @@ -37,7 +37,7 @@ Here's a bare-minimum example of using WebGear_RTC API with the Raspberry Pi cam === "New Picamera2 backend" - ```python + ```python linenums="1" hl_lines="19" # import libs import uvicorn from libcamera import Transform @@ -76,7 +76,7 @@ Here's a bare-minimum example of using WebGear_RTC API with the Raspberry Pi cam !!! note "You could also enforce the legacy picamera API backend in PiGear by using the [`enforce_legacy_picamera`](../../gears/pigear/params) user-defined optional parameter boolean attribute." - ```python + ```python linenums="1" hl_lines="18" # import libs import uvicorn from vidgear.gears.asyncio import WebGear_RTC @@ -110,7 +110,7 @@ Here's a bare-minimum example of using WebGear_RTC API with the Raspberry Pi cam Here's an example of using WebGear_RTC API with real-time Video Stabilization enabled: -```python +```python linenums="1" hl_lines="11" # import libs import uvicorn from vidgear.gears.asyncio import WebGear_RTC @@ -139,7 +139,7 @@ In this example, we'll be displaying two video feeds side-by-side simultaneously ??? new "New in v0.2.4" This example was added in `v0.2.4`. -```python hl_lines="10-22 26-92 97-101" +```python linenums="1" hl_lines="10-22 26-92 97-101" # import necessary libs import uvicorn, cv2 import numpy as np diff --git a/docs/help/writegear_ex.md b/docs/help/writegear_ex.md index 97a2d6193..00df4cf3b 100644 --- a/docs/help/writegear_ex.md +++ b/docs/help/writegear_ex.md @@ -38,7 +38,7 @@ In Compression Mode, you can use WriteGear for livestreaming with traditional pr !!! danger "Make sure to change RTSP address `rtsp://localhost:8554/mystream` with yours in following code before running!" -```python hl_lines="10 15" +```python linenums="1" hl_lines="10 15" # import required libraries import cv2 from vidgear.gears import CamGear @@ -94,7 +94,7 @@ In Compression Mode, you can also use WriteGear for Youtube-Livestreaming. The e === "Without Audio" - ```python hl_lines="11-17 21 25" + ```python linenums="1" hl_lines="11-17 21 25" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -150,7 +150,7 @@ In Compression Mode, you can also use WriteGear for Youtube-Livestreaming. The e !!! warning "This code assume given input video source contains valid audio stream." - ```python hl_lines="7 15-24 28 32" + ```python linenums="1" hl_lines="7 15-24 28 32" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -265,7 +265,7 @@ With WriteGear's Compression Mode, you can directly feed video-frames to [`v4l2l -```python hl_lines="12-15 19" +```python linenums="1" hl_lines="12-15 19" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -323,7 +323,7 @@ In Compression Mode, you can also use WriteGear for creating MP4 segments from a ??? new "New in v0.2.1" This example was added in `v0.2.1`. -```python hl_lines="13-20 24" +```python linenums="1" hl_lines="13-20 24" # import required libraries from vidgear.gears import VideoGear from vidgear.gears import WriteGear @@ -394,7 +394,7 @@ You can also use WriteGear for merging external audio with live video-source: !!! failure "Make sure this `-i` audio-source it compatible with provided video-source, otherwise you could encounter multiple errors or no output at all." -```python hl_lines="11-12" +```python linenums="1" hl_lines="11-12" # import required libraries from vidgear.gears import CamGear from vidgear.gears import WriteGear @@ -458,9 +458,9 @@ If you need timely accurate video with exactly same speed as real-time input, th In this example we are capturing video from desktop screen in a Timely Accurate manner. -=== "Windows" +=== "Windows :fontawesome-brands-windows:" - ```python hl_lines="8-17" + ```python linenums="1" hl_lines="8-17" # import required libraries from vidgear.gears import WriteGear @@ -486,9 +486,9 @@ In this example we are capturing video from desktop screen in a Timely Accurate writer.close() ``` -=== "Linux" +=== "Linux :material-linux:" - ```python hl_lines="8-17" + ```python linenums="1" hl_lines="8-17" # import required libraries from vidgear.gears import WriteGear @@ -514,9 +514,9 @@ In this example we are capturing video from desktop screen in a Timely Accurate writer.close() ``` -=== "macOS" +=== "MacOS :material-apple:" - ```python hl_lines="8-17" + ```python linenums="1" hl_lines="8-17" # import required libraries from vidgear.gears import WriteGear @@ -557,7 +557,7 @@ In this example, we'll create a node that listens to a ROS image message topic, !!! note "This example is vidgear implementation of this [wiki example](http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython)." -```python +```python linenums="1" # import roslib import roslib diff --git a/docs/overrides/main.html b/docs/overrides/main.html index a5a6e9d07..70bfe924d 100644 --- a/docs/overrides/main.html +++ b/docs/overrides/main.html @@ -20,8 +20,9 @@ {% block announce %} - {% include ".icons/material/message-alert.svg" %} We're excited to announce our new Deffcode library, + {% include ".icons/fontawesome/solid/bullhorn.svg" %} We're excited to announce our + new Deffcode + library, which will be integrated with VidGear soon. We value your feedback and would love to hear your thoughts! {% endblock %} diff --git a/docs/switch_from_cv.md b/docs/switch_from_cv.md index d39dba131..276c4020f 100644 --- a/docs/switch_from_cv.md +++ b/docs/switch_from_cv.md @@ -61,7 +61,7 @@ Let's compare a bare-minimum python code for extracting frames out of any Webcam === "OpenCV VideoCapture Class" - ```python hl_lines="5 11 14-15 33" + ```python hl_lines="5 11 14 33" # import required libraries import cv2 @@ -99,7 +99,7 @@ Let's compare a bare-minimum python code for extracting frames out of any Webcam === "VidGear's CamGear API" - ```python hl_lines="6 12 15-16 34" + ```python hl_lines="6 12 15 34" # import required libraries from vidgear.gears import CamGear import cv2 diff --git a/mkdocs.yml b/mkdocs.yml index d046fd715..e8f8f9759 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -55,7 +55,7 @@ theme: palette: - media: "(prefers-color-scheme)" toggle: - icon: material/weather-sunny-off + icon: material/weather-hazy name: Switch to light mode # Light mode - media: "(prefers-color-scheme: light)" @@ -72,7 +72,7 @@ theme: accent: orange toggle: icon: material/weather-night - name: Switch to light mode + name: Switch to system mode font: text: Source Sans 3 code: Fira Code