Kindly go through each given examples thoroughly, any incorrect settings/parameter may result in errors or no output at all.
NetGear provides auto-termination feature, where if you terminate server end manually, the connected client(s) end will also terminate themselves to save resources.
Only either of two functions (i.e. send() and recv()) can be accessed at any given instance based on activated primary mode selected during NetGear API initialization. Trying to access wrong function in incorrect mode (for e.g using send() function in Receive Mode), will result in ValueError.
After going through following Usage Examples, Checkout more bonus examples here ➶
# import required librariesfromvidgear.gearsimportVideoGearfromvidgear.gearsimportNetGear# open any valid video stream(for e.g `test.mp4` file)stream=VideoGear(source="test.mp4").start()# Define Netgear Server with default parametersserver=NetGear()# loop over until KeyBoard InterruptedwhileTrue:try:# read frames from streamframe=stream.read()# check for frame if NonetypeifframeisNone:break# {do something with the frame here}# send frame to serverserver.send(frame)exceptKeyboardInterrupt:break# safely close video streamstream.stop()# safely close serverserver.close()
# import required librariesfromvidgear.gearsimportNetGearimportcv2# define Netgear Client with `receive_mode = True` and default parameterclient=NetGear(receive_mode=True)# loop overwhileTrue:# receive frames from networkframe=client.recv()# check for received frame if NonetypeifframeisNone:break# {do something with the frame here}# Show output windowcv2.imshow("Output Frame",frame)# check for 'q' key if pressedkey=cv2.waitKey(1)&0xFFifkey==ord("q"):break# close output windowcv2.destroyAllWindows()# safely close clientclient.close()
Open a terminal on Client System (where you want to display the input frames received from the Server) and execute the following python code:
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 for this purpose.
You can terminate client anytime by pressing Ctrl+C on your keyboard!
# import required librariesfromvidgear.gearsimportNetGearimportcv2# define various tweak flagsoptions={"flag":0,"copy":True,"track":False}# Define Netgear Client at given IP address and define parameters # !!! change following IP address '192.168.x.xxx' with yours !!!client=NetGear(address="192.168.x.xxx",port="5454",protocol="tcp",pattern=1,receive_mode=True,logging=True,**options)# loop overwhileTrue:# receive frames from networkframe=client.recv()# check for received frame if NonetypeifframeisNone:break# {do something with the frame here}# Show output windowcv2.imshow("Output Frame",frame)# check for 'q' key if pressedkey=cv2.waitKey(1)&0xFFifkey==ord("q"):break# close output windowcv2.destroyAllWindows()# safely close clientclient.close()
# import required librariesfromvidgear.gearsimportVideoGearfromvidgear.gearsimportNetGear# define various tweak flagsoptions={"flag":0,"copy":True,"track":False}# Open live video stream on webcam at first index(i.e. 0) devicestream=VideoGear(source=0).start()# 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 InterruptedwhileTrue:try:# read frames from streamframe=stream.read()# check for frame if NonetypeifframeisNone:break# {do something with the frame here}# send frame to serverserver.send(frame)exceptKeyboardInterrupt:break# safely close video streamstream.stop()# safely close serverserver.close()
Open a terminal on Client System (where you want to display the input frames received from the Server) and execute the following python code:
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 for this purpose.
You can terminate client anytime by pressing Ctrl+C on your keyboard!
# import required librariesfromvidgear.gearsimportNetGearimportcv2# define tweak flagsoptions={"flag":0,"copy":True,"track":False}# Define Netgear Client at given IP address and define parameters # !!! change following IP address '192.168.x.xxx' with yours !!!client=NetGear(address="192.168.x.xxx",port="5454",protocol="tcp",pattern=0,receive_mode=True,logging=True,**options)# loop overwhileTrue:# receive frames from networkframe=client.recv()# check for received frame if NonetypeifframeisNone:break# {do something with the received frame here}# Show output windowcv2.imshow("Output Frame",frame)# check for 'q' key if pressedkey=cv2.waitKey(1)&0xFFifkey==ord("q"):break# close output windowcv2.destroyAllWindows()# safely close clientclient.close()
# import required librariesfromvidgear.gearsimportNetGearimportcv2# Open suitable video stream, such as webcam on first index(i.e. 0)stream=cv2.VideoCapture(0)# define tweak flagsoptions={"flag":0,"copy":True,"track":False}# Define Netgear Client at given IP address and define parameters # !!! change following IP address '192.168.x.xxx' with yours !!!client=NetGear(address="192.168.x.xxx",port="5454",protocol="tcp",pattern=0,logging=True,**options)# loop over until KeyBoard InterruptedwhileTrue:try:# read frames from stream(grabbed,frame)=stream.read()# check for frame if not grabbedifnotgrabbed:break# {do something with the frame here}# send frame to serverserver.send(frame)exceptKeyboardInterrupt:break# safely close video streamstream.release()# safely close serverserver.close()
Open a terminal on Client System (where you want to display the input frames received from the Server) and execute the following python code:
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 for this purpose.
You can terminate client anytime by pressing Ctrl+C on your keyboard!
# import required librariesfromvidgear.gearsimportNetGearimportcv2# define various tweak flagsoptions={"flag":0,"copy":True,"track":False}# Define Netgear Client at given IP address and define parameters # !!! change following IP address '192.168.x.xxx' with yours !!!client=NetGear(address="192.168.x.xxx",port="5454",protocol="tcp",pattern=1,receive_mode=True,logging=True,**options)# loop overwhileTrue:# receive frames from networkframe=client.recv()# check for received frame if NonetypeifframeisNone:break# {do something with the frame here}# Show output windowcv2.imshow("Output Frame",frame)# check for 'q' key if pressedkey=cv2.waitKey(1)&0xFFifkey==ord("q"):break# close output windowcv2.destroyAllWindows()# safely close clientclient.close()
Now, Open the terminal on another Server System (let's say you want to transmit Monitor Screen Frames from a Laptop), and execute the following python code:
Replace the IP address in the following code with Client's IP address you noted earlier.
You can terminate stream on both side anytime by pressing Ctrl+C on your keyboard!
# import required librariesfromvidgear.gearsimportScreenGearfromvidgear.gearsimportNetGear# define various tweak flagsoptions={"flag":0,"copy":True,"track":False}# Start capturing live Monitor screen frames with default settingsstream=ScreenGear().start()# 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 InterruptedwhileTrue:try:# read frames from streamframe=stream.read()# check for frame if NonetypeifframeisNone:break# {do something with the frame here}# send frame to serverserver.send(frame)exceptKeyboardInterrupt:break# safely close video streamstream.stop()# safely close serverserver.close()