ViduSdk icon indicating copy to clipboard operation
ViduSdk copied to clipboard

A bug in python wrapper.

Open Derick317 opened this issue 2 years ago • 3 comments

I ran the following Python code and caught a bug:

import pyokulo as okulo
import cv2 as cv
import numpy as np
import time
from camera import Camera

class Okulo(Camera):
    """Okulo camera for reinforcement learning"""
    def __init__(self, c2w) -> None:
        """
        Initiate a new camera
        
        We need to take an RGB image and a point cloud simultaneously, so we need
        the RGB stream and the ToF stream.
        """
        intrinsic = okulo.intrinsics()
        extrinsic = okulo.extrinsics()
        device = okulo.PDdevice()

        if not device.init():
            print("device init failed")
            exit(-1)
        print("device init succeed")
        self.streams = dict()
        for i in range(1):
            stream = okulo.PDstream(device, i)
            suc = stream.init()
            streamName = stream.getStreamName()
            assert suc, "{} stream init failed!\n".format(streamName)
            print("{} stream init success.".format(streamName))
            assert streamName in ("RGB", "ToF")
            self.streams[streamName] = stream
            start_time = time.time()
            for _ in range(200):
                mats = stream.getPyMat()
            print("Using {} s to take 200 RGB images".format(time.time() - start_time))
            
    def get_rgb(self) -> np.ndarray:
        mats = list()
        while not mats:
            mats = self.streams["RGB"].getPyMat()
            print(123, end='')
        rgb = mats[0]
        return rgb

if __name__ == "__main__":
    camera = Okulo(22)
    rgb = camera.get_rgb()
    print(rgb.shape)

The following text was printed in the terminal:

[INFO] (Func init): 
deviceID 000002F9955CD3C2 
device init succeed
RGB stream init success.
Using 0.4114401340484619 s to take 100 RGB images
free(): double free detected in tcache 2

The shape of the array representing the RGB image was not printed. When I tried to run the code again, it does still not work. However, free(): double free detected in tcache 2 disappeared. Only the following text remained:

[INFO] (Func init): 
deviceID 000002F9955CD3C2 
device init succeed
RGB stream init success.
Using 0.3311343193054199 s to take 100 RGB images

Derick317 avatar Nov 14 '22 09:11 Derick317