Ask Your Question
0

python requests mjpeg url

asked 2019-04-22 01:26:36 -0500

updated 2019-04-22 02:27:23 -0500

berak gravatar image

frame = cv2.imdecode(np.asarray(bytearray(jpg), dtype=np.uint8), cv2.IMREAD_COLOR) this line error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:726: error: (-215:Assertion failed) !buf.empty() && buf.isContinuous() in function 'cv::imdecode_' What should I do? i will be waiting for your reply

edit retag flag offensive close merge delete

Comments

your bytearray(jpg)) is something else than expected (probably an error msg / tuple)

please check, and refrain from using shortcuts like x(y(z(a(b(c()))))).

(do one step at a time, so you can debug it properly)

berak gravatar imageberak ( 2019-04-22 02:26:38 -0500 )edit

My code this,give me that after a while writing error.I run debug mode but I don't find error

r = requests.get('url', auth=HTTPDigestAuth('usernam', 'pass'), stream=True)               
if(r.status_code == 200):
   bytes=b'' 
   for chunk in r.iter_content(chunk_size=1024):
    bytes += chunk
    finda = bytes.find(b'\xff\xd8')
    findb = bytes.find(b'\xff\xd9')
    if finda != -1 and findb != -1:
      jpg = bytes[finda:findb+2]
      bytes = bytes[findb+2:]
      frame = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8), cv2.IMREAD_COLOR)
      if frame is not None:
         cv2.imshow('Live',frame)
         if cv2.waitKey(1) == 27:
           exit(0)
Büşranur gravatar imageBüşranur ( 2019-04-22 03:11:25 -0500 )edit

what is

 bytes = bytes[findb+2:]

needed for ?

berak gravatar imageberak ( 2019-04-22 05:49:50 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2019-04-22 05:45:03 -0500

supra56 gravatar image

I have 2 links . If you are using python 3.x, You need to install urllib2. request and urllib. You can modified either or both snippet.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-04-22 01:26:36 -0500

Seen: 59 times

Last updated: Apr 22