hi all
first off, i'm no python expert. so this code is hacked together.
its basically semi working, but from the screenshot u can see the colour is weird and there's weird banding
the code is taken from the Spektacular SDK examples mapping_ar.py

here's the relevant function: (sorry, the couldn't get the code formatting to work properly, so had to manualy do it)
<code>
def handleVioOutput(state, cameraPose, t, img, width, height, video_frame, ndi_send):
if state.shouldQuit:
ndi.send_destroy(ndi_send)
ndi.destroy()
return
if not state.displayInitialized:
state.displayInitialized = True
targetWidth = 640
targetHeight = 360
state.scale = min(targetWidth / width, targetHeight / height)
state.adjustedResolution = [int(state.scale * width), int(state.scale * height)]
init_display(state.adjustedResolution[0], state.adjustedResolution[1])
print(state.adjustedResolution[0], state.adjustedResolution[1])
state.meshRenderer = MeshRenderer()
state.pointCloudRenderer = PointCloudRenderer(state.args.pointCloudDensity)
if state.mesh:
state.meshRenderer.setMesh(state.mesh)
for event in pygame.event.get():
if event.type == pygame.QUIT:
state.shouldQuit = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q: state.shouldQuit = True
if event.key == pygame.K_x:
state.args.pointCloud = not state.args.pointCloud
if event.key == pygame.K_m:
if state.meshRenderer:
state.meshRenderer.nextMode()
if state.pointCloudRenderer:
state.pointCloudRenderer.nextMode()
if state.shouldQuit:
pygame.quit()
return
glPixelZoom(state.scale, state.scale) glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, img.data)
updateRenderer(state, cameraPose, t)
pixel_data = np.zeros((state.adjustedResolution[1], state.adjustedResolution[0], 3), dtype=np.uint8)
img = glReadPixels(0, 0, state.adjustedResolution[0], state.adjustedResolution[1], GL_RGB, GL_UNSIGNED_BYTE, pixel_data)
#img_bgr = cv.cvtColor(img, cv.COLOR_RGB2BGR)
video_frame.data = img video_frame.FourCC = ndi.FOURCC_VIDEO_TYPE_BGRX
ndi.send_send_video_v2(ndi_send, video_frame)
if state.currentMapperOutput:
state.lastMapperOutput = state.currentMapperOutput
if state.args.recordPath:
try: os.makedirs(os.path.dirname(state.args.recordPath)) except: pass
if os.name == 'nt':
ffmpegStdErrToNull = "2>NUL"
else:
ffmpegStdErrToNull = "2>/dev/null"
r = state.adjustedResolution
if state.recordPipe is None:
cmd = "ffmpeg -y -f rawvideo -vcodec rawvideo -pix_fmt rgb24 -s {}x{} -i - -an -pix_fmt yuv420p -c:v libx264 -vf vflip -crf 17 \"{}\" {}".format( r[0], r[1], state.args.recordPath, ffmpegStdErrToNull)
state.recordPipe = subprocess.Popen( cmd, stdin=subprocess.PIPE, shell=True)
buffer = glReadPixels(0, 0, r[0], r[1], GL_RGB, GL_UNSIGNED_BYTE)
state.recordPipe.stdin.write(buffer)
pygame.display.flip()
</code>