petergu684 / HoloLens2-ResearchMode-Unity

Unity Plugin for using research mode functionality in HoloLens 2. Modified based on HoloLens2ForCV.
MIT License
202 stars 59 forks source link

How can I use python on my PC to display the current depth image #39

Closed daijava666 closed 2 years ago

daijava666 commented 2 years ago

Hi @petergu684 , First of all, thanks for your work, and t has helped me a lot. Now, I have a question to ask you. I've used python on the PC to get the m_depthMap specifics, the code is as follows, but during execution, the PC does not display the currently received depth image, what is the cause of this? Thank you very much for your answer!

            `while True:
                     header = recv_nbytes(client_socket, 4)
                     if header is None:
                          break
                     header = np.frombuffer(header, dtype=np.uint32)
                     depthImageLength = header[0]
                     print('depthImageLength is ' + str(depthImageLength))
                     depthImageData = recv_nbytes(client_socket, depthImageLength)
                     print('len(depthImageData) is ' + str(len(depthImageData)))
                     depthImage = np.frombuffer(depthImageData, np.uint16).reshape(512, 512)
                     print('len(depthImage) is ' + str(len(depthImage)))
                     self.last_frame = depthImage

                def main():

                     print('start')
                     receiver = VideoReceiver('', 50002)
                     receiver.start()
                     fig, ax = plt.subplots()

                     def func_animate(_):
                          if receiver.last_frame is not None:
                             ax.cla()
                             ax.imshow(receiver.last_frame)

                     ani = FuncAnimation(fig,
                                    func_animate,
                                    frames=10,
                                    interval=50)
                     plt.tight_layout()
                     plt.show()`