在python中的进程之间共享内存

时间:2018-05-19 13:04:09

标签: python multiprocessing

按照this question和其他几个人给出的说明,我尝试在进程之间共享内存但我找不到正确传递对象的正确方法。我尝试了以下代码,但我得到“TypeError:track_()需要1个位置参数,但921600给出了”

controller.py:

import multiprocessing as mp
import numpy as np
from capture import f
from tracking import track_
import cv2
import time
#import sharedmem
import ctypes

shared_color_base = mp.Array(ctypes.c_uint8, 480*640*3)
shared_depth_base = mp.Array(ctypes.c_ushort, 480*640)
shared_color_ = np.ctypeslib.as_array(shared_color_base.get_obj())
shared_color_ = shared_color_.reshape(480, 640, -1)
shared_depth_ = np.ctypeslib.as_array(shared_depth_base.get_obj())
shared_depth_ = shared_depth_.reshape(480, 640)

_run = True
p = mp.Process(target=f, args=(shared_color_, shared_depth_, _run))
p.start()
p2 = mp.Process(target=track_, args=(shared_color_base))
p2.start()
#Converting to numpy array:
#depth_[:] = np.frombuffer(np.asanyarray(aligned_depth_frame.get_data(), dtype=np.uint16).reshape(480, 640)
#color_[:] = np.frombuffer(np.asanyarray(color_frame.get_data()), dtype=np.uint8).reshape(480, 640, -1)
if __name__ == '__main__':
        //

tracking.py:

import cv2
import numpy as np

def track_(sh_mem):    
    tracker = cv2.TrackerKCF_create()
    with sh_mem.get_lock():
        frame = np.asanyarray(sh_mem.get_obj())

提前致谢。

0 个答案:

没有答案