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

Could some one help me. How to solve Oak-D pro camera data decoding and display #14

Open
jaiminlee opened this issue Jun 28, 2022 · 0 comments

Comments

@jaiminlee
Copy link

jaiminlee commented Jun 28, 2022

#every time different frame data size
#May be it is commpress data

#this is my code

import cv2
import config
import depthai as dai
import subprocess as sp
from os import name as osName
import numpy as np
import h264decoder
import matplotlib.pyplot as pyplot
import sys

''' Create pipeline'''
pipeline = dai.Pipeline()

''' Define sources and output '''
camRgb = pipeline.create(dai.node.ColorCamera)
videoEnc = pipeline.create(dai.node.VideoEncoder)
xout = pipeline.create(dai.node.XLinkOut)

xout.setStreamName("h264")

''' Properties '''
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
videoEnc.setDefaultProfilePreset(camRgb.getVideoSize(), camRgb.getFps(), dai.VideoEncoderProperties.Profile.H264_MAIN)

''' Linking '''
camRgb.video.link(videoEnc.input)
videoEnc.bitstream.link(xout.input)

''' video_in = cv2.VideoCapture("udpsrc port=12345 ! application/x-rtp-stream,encoding-name=JPEG ! rtpstreamdepay ! ''' rtpjpegdepay ! jpegdec ! videoconvert ! appsink", cv2.CAP_GSTREAMER)
video_out = cv2.VideoWriter("appsrc ! videoconvert ! jpegenc ! rtpjpegpay ! rtpstreampay ! udpsink host=[destination-ip] port=12344", cv2.CAP_GSTREAMER, 0, 24, (1920, 1080), True)

img = None
fig, ax = pyplot.subplots(1,1)

''' video_in = cv2.VideoCapture("udpsrc port=12345 ! application/x-rtp-stream,encoding-name=JPEG ! rtpstreamdepay !''' rtpjpegdepay ! jpegdec ! videoconvert ! appsink", cv2.CAP_GSTREAMER)
video_out = cv2.VideoWriter("appsrc ! videoconvert ! jpegenc ! rtpjpegpay ! rtpstreampay ! udpsink host=[destination-ip] port=12344", cv2.CAP_GSTREAMER, 0, 24, (1920, 1080), True)

img = None
fig, ax = pyplot.subplots(1,1)

def display(framedata):
global img, fig, ax
(frame, w, h, ls) = framedata
print(w,' ',h,' ',ls)
if frame is not None:
print('frame size %i bytes, w %i, h %i, linesize %i' % (len(frame), w, h, ls))
frame = np.frombuffer(frame, dtype=np.ubyte, count=len(frame))
frame = frame.reshape((h, ls//3, 3))
frame = frame[:,:w,:]

if not img:
    img = ax.imshow(frame)
    pyplot.show(block = False)
else:
    img.set_data(frame)
    pyplot.draw()
pyplot.pause(0.001)

''' Two APIs to decode frames'''
def run_decode_frame(decoder, data_in):
while len(data_in):
''' One frame at a time, indicating how much of the input has been consumed.'''
framedata, nread = decoder.decode_frame(data_in)
data_in = data_in[nread:]
display(framedata)
def run_decode(decoder, data_in):
''' Consume the input completely. May result in multiple frames read.'''
''' This runs a bit faster than the other way.'''
framedatas = decoder.decode(data_in)
for framedata in framedatas:
display(framedata)

def send():
''' Connect to device and start pipeline'''
with dai.Device(pipeline) as device:
print("Oak-D")
''' Output queue will be used to get the encoded data from the output defined above'''
q = device.getOutputQueue(name="h264", maxSize=30, blocking=True)
decoder = h264decoder.H264Decoder()
try:
while True:
frame = q.get().getData() # Blocking call, will wait until new data has arrived
run_decode(decoder, frame)
'''cv2.imshow('Original', data)'''
key = cv2.waitKey(1) & 0xff
if key == 27:
break
except:
print("Exception")
pass
'''cv2.destroyAllWindows()'''
video_out.release()

if name == 'main':
send()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant