1

I am running a GUI with kivy, and simultaneously processing some realtime 3D scanner data. I'm using a multiprocessing instance to process the scan data, while the kivy GUI runs. The scanner data is read in by OpenCV, frame by frame.

My issue is that I can share the scanner data with the kivy instance, in order to display it within the GUI. I have tried making the the array "frame" global, but that doesn't seem to be doing the trick.

I have read about the multiprocessing manager, but im unclear on how to use it to manage a numpy array.

frame = np.zeros((480,640))

class CamApp(App):

    def update_slider(self, instance, value):
        #print(value)
        self.slider_value = value*3

    def build(self):
        self.img1=Image()
        layout = GridLayout(cols = 1)
        layout.add_widget(self.img1)
        Clock.schedule_interval(self.update, 1.0/33.0)
        return layout

    def update(self, dt):
        global frame

        #format as texture
        buf1 = cv2.flip(frame, 0)
        buf = buf1.tobytes()
        texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr') 
        texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')

        # display image from the texture
        self.img1.texture = texture1

def cam(message):
    print(message)
    dc = DepthCamera()
    global frame

    while True:
        ret, depth_frame, colour_frame = dc.get_frame()
        frame = cv2.applyColorMap(cv2.convertScaleAbs(depth_frame, alpha=0.2), cv2.COLORMAP_BONE)

        #cv2.imshow("Depth frame", frame)
        #cv2.imshow("Color frame", colour_frame)
        #key = cv2.waitKey(1)




if __name__ == '__main__':
    p = Process(target=cam, args=('beginning capture',))
    p.start()
    CamApp().run()
    cv2.destroyAllWindows()
John G
  • 11
  • 1
  • 1
    hi, perhaps this might be of interest https://stackoverflow.com/questions/9754034/can-i-create-a-shared-multiarray-or-lists-of-lists-object-in-python-for-multipro https://stackoverflow.com/questions/7894791/use-numpy-array-in-shared-memory-for-multiprocessing – jspcal Oct 23 '21 at 01:08
  • By definition, sharing is very limited in multiprocessing. Each thread has its own copy of the array that doesn’t interact with the others. – Frank Yellin Oct 23 '21 at 02:21

0 Answers0