buresu / ndi-python

NewTek NDI Python wrapper
MIT License
133 stars 30 forks source link

Process closes without reason using CV2 #33

Open simplo opened 7 months ago

simplo commented 7 months ago

Hi, I'm trying to use NDI to process some image from another software with CV2, so, at the moment, I just trasformed the received fram in numpy array and display it. After a few seconds I get this message: Process finished with exit code -1073741819 (0xC0000005). I'm using Python 3.9.18 on Windows 10 in a I7 7th generation

This is the code:

import sys import numpy as np import NDIlib as ndi import cv2

def main():

if not ndi.initialize():
    return 0

ndi_find = ndi.find_create_v2()

if ndi_find is None:
    return 0

sources = []
while not len(sources) > 1:
    print('Looking for sources ...')
    ndi.find_wait_for_sources(ndi_find, 1000)
    sources = ndi.find_get_current_sources(ndi_find)

for i, s in enumerate(sources):
    print('%s. %s' % (i + 1, s.ndi_name))

ndi_recv_create = ndi.RecvCreateV3()
ndi_recv_create.color_format = ndi.RECV_COLOR_FORMAT_BGRX_BGRA

ndi_recv = ndi.recv_create_v3(ndi_recv_create)

if ndi_recv is None:
    return 0

ndi.recv_connect(ndi_recv, sources[1])

ndi.find_destroy(ndi_find)

while True:
    t, v, a, _ = ndi.recv_capture_v2(ndi_recv, 5000)

    if t == ndi.FRAME_TYPE_NONE:
        print('No data received.')
        continue

    if t == ndi.FRAME_TYPE_VIDEO:

        print('Video data received (%dx%d).' % (v.xres, v.yres))
        ndi.recv_free_video_v2(ndi_recv, v)
        image = np.copy(v.data)
        cv2.imshow('NDI', image)
        continue

    if t == ndi.FRAME_TYPE_AUDIO:
        print('Audio data received (%d samples).' % a.no_samples)
        ndi.recv_free_audio_v2(ndi_recv, a)
        continue

ndi.recv_destroy(ndi_recv)

ndi.destroy()

return 0

if name == "main": sys.exit(main())

simplo commented 7 months ago

FIXED: it was my fault, the ndi.recv_free_video_v2(ndi_recv, v) command was placed before the image process...