Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: value error when using screengear with netgear #327

Closed
3 tasks done
amarco opened this issue Jul 15, 2022 · 2 comments
Closed
3 tasks done

[Bug]: value error when using screengear with netgear #327

amarco opened this issue Jul 15, 2022 · 2 comments
Labels
QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING TO TEST ⏲️ Asked user to test the suggested example/binary/solution

Comments

@amarco
Copy link

amarco commented Jul 15, 2022

Description

New to vidgear, I started by using the following code based on the example:

# import required libraries
from vidgear.gears import ScreenGear
from vidgear.gears import NetGear

# open video stream with defined parameters with monitor at index `1` selected
stream = ScreenGear(monitor=1, logging=True).start()

options = {"flag": 0, "copy": False, "track": False}
server = NetGear(
    address="10.212.110.3",
    port="5454",
    protocol="tcp",
    pattern=1,
    logging=True,
    **options
)

# loop over
while True:

    try:
        # read frames from stream
        frame = stream.read()
    
        # check for frame if Nonetype
        if frame is None:
            break

        server.send(frame)
    except KeyboardInterrupt:
        break
    

# safely close video stream
stream.stop()
server.close()

get the following error and abort of execution. Is there a workaround?

c:\Users\ma\OneDrive - RWDI\Desktop\devel\dstream>python producerv2.py
13:12:08 ::    Helper     ::   INFO   :: Running VidGear Version: 0.2.6
13:12:08 ::  ScreenGear   ::  DEBUG   :: Enabling Threaded Queue Mode by default for ScreenGear!
13:12:08 ::    NetGear    ::  DEBUG   :: Reliable transmission is enabled for this pattern with max-retries: 3 and timeout: 4.0 secs.
13:12:08 ::    NetGear    ::  DEBUG   :: Successfully connected to address: tcp://10.212.110.3:5454 with pattern: 1.
13:12:08 ::    NetGear    ::  DEBUG   :: JPEG Frame-Compression is activated for this connection with Colorspace:`BGR`, Quality:`90`%, Fastdct:`enabled`, and Fastupsample:`disabled`.
13:12:08 ::    NetGear    ::  DEBUG   :: Unique System ID is Q7A4RFHL.
13:12:08 ::    NetGear    ::  DEBUG   :: Send Mode is successfully activated and ready to send data.
Traceback (most recent call last):
  File "c:\Users\ma\OneDrive - RWDI\Desktop\devel\dstream\producerv2.py", line 42, in <module>
    server.send(frame)
  File "C:\WinPython\WPy64-39100\python-3.9.10.amd64\lib\site-packages\vidgear\gears\netgear.py", line 1260, in send
    frame = simplejpeg.encode_jpeg(
  File "simplejpeg/_jpeg.pyx", line 440, in simplejpeg._jpeg.encode_jpeg
ValueError: 4 channels does not match given colorspace BGR

Issue Checklist

  • I have searched open or closed issues for my problem and found nothing related or helpful.
  • I have read the Documentation and found nothing related to my problem.
  • I've read the Issue Guidelines and wholeheartedly agree.

Expected behaviour

not expecting a crash

Actual behaviour

should not crash

Steps to reproduce

use sample code in windows 10

Terminal log output

No response

Python Code

No response

VidGear Version

0.2.4

Python version

3.9.10

OpenCV version

4.6.0

Operating System version

windows 10

Any other Relevant Information?

No response

@amarco amarco added the BUG 🐛 Vidgear api's error, flaw or fault label Jul 15, 2022
@welcome
Copy link

welcome bot commented Jul 15, 2022

Thanks for opening this issue, a maintainer will get back to you shortly!

In the meantime:

  • Read our Issue Guidelines, and update your issue accordingly. Please note that your issue will be fixed much faster if you spend about half an hour preparing it, including the exact reproduction steps and a demo.
  • Go comprehensively through our dedicated FAQ & Troubleshooting section.
  • For any quick questions and typos, please refrain from opening an issue, as you can reach us on Gitter community channel.

@abhiTronix
Copy link
Owner

abhiTronix commented Jul 15, 2022

Traceback (most recent call last):
File "c:\Users\ma\OneDrive - RWDI\Desktop\devel\dstream\producerv2.py", line 42, in
server.send(frame)
File "C:\WinPython\WPy64-39100\python-3.9.10.amd64\lib\site-packages\vidgear\gears\netgear.py", line 1260, in send
frame = simplejpeg.encode_jpeg(
File "simplejpeg/_jpeg.pyx", line 440, in simplejpeg._jpeg.encode_jpeg
ValueError: 4 channels does not match given colorspace BGR

@amarco This is not a bug.

You're using monitor=1 in ScreenGear API, which will output BGRA colorspace frames instead of default BGR(See https://abhitronix.github.io/vidgear/latest/gears/screengear/usage/#using-screengear-with-multiple-screens).

But NetGear API on other hand expects BGR frames by default:

self.__jpeg_compression_colorspace = "BGR" # use BGR colorspace by default

and is incompatible with BGRA frames from ScreenGear API.

 

Solution:

There are two solutions to this problem and you can use any one of them to resolve this issue.

Solution-1: Change colorspace to BGRA in NetGear API

# import required libraries
from vidgear.gears import ScreenGear
from vidgear.gears import NetGear

# open video stream with defined parameters with monitor at index `1` selected
stream = ScreenGear(monitor=1, logging=True).start()

# change colorspace to `BGRA`
options = {"flag": 0, "copy": False, "track": False, "jpeg_compression":"BGRA"}
server = NetGear(
    address="10.212.110.3",
    port="5454",
    protocol="tcp",
    pattern=1,
    logging=True,
    **options
)

# loop over
while True:

    try:
        # read frames from stream
        frame = stream.read()
    
        # check for frame if Nonetype
        if frame is None:
            break

        server.send(frame)
    except KeyboardInterrupt:
        break
    

# safely close video stream
stream.stop()
server.close()

Solution-2: Remove monitor=1 in ScreenGear API

# import required libraries
from vidgear.gears import ScreenGear
from vidgear.gears import NetGear

# open video stream with defined parameters
stream = ScreenGear(logging=True).start()

options = {"flag": 0, "copy": False, "track": False}
server = NetGear(
    address="10.212.110.3",
    port="5454",
    protocol="tcp",
    pattern=1,
    logging=True,
    **options
)

# loop over
while True:

    try:
        # read frames from stream
        frame = stream.read()
    
        # check for frame if Nonetype
        if frame is None:
            break

        server.send(frame)
    except KeyboardInterrupt:
        break
    

# safely close video stream
stream.stop()
server.close()

@abhiTronix abhiTronix added QUESTION ❓ User asked about the working/usage of VidGear APIs. WAITING TO TEST ⏲️ Asked user to test the suggested example/binary/solution SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! and removed BUG 🐛 Vidgear api's error, flaw or fault labels Jul 15, 2022
@abhiTronix abhiTronix removed their assignment Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QUESTION ❓ User asked about the working/usage of VidGear APIs. SOLVED 🏁 This issue/PR is resolved now. Goal Achieved! WAITING TO TEST ⏲️ Asked user to test the suggested example/binary/solution
Projects
None yet
Development

No branches or pull requests

2 participants