Example #1
0
 def _open(self):
     ret = libatlas.OpenCameraEx(self._id, self._fps, 
                                 self._width, self._height)
     if (ret != CAMERA_OK):
         acl_logger.log_error("ERROR:Open camera %d failed ,ret = %d " % (self._id, ret))
         return CAMERA_ERROR
     self._status = CAMERA_OPENED
     return CAMERA_OK
Example #2
0
    def read(self):
        frame_data = CameraOutputC()
        ret = libatlas.ReadCameraFrame(self._id, byref(frame_data))
        if (ret != CAMERA_OK):
            log_error("ERROR:Read camera %d failed" % (self._id))
            return None

        return AclImage(addressof(frame_data.data.contents), self._width,
                        self._height, self._size, MEMORY_DVPP)
Example #3
0
    def _keep_alive(self):
        msg = pm.heartbeat_message()

        while True:
            if self._closed:
                log_error("Heard beat thread exit")
                break

            self.socket.send_msg(msg)
            time.sleep(2)
Example #4
0
 def __init__(self, name):
     self._name = name
     self._channel_id = self._open(name)
     if self._channel_id == INVALID_CHANNEL_ID:
         self._is_opened = False
         acl_logger.log_error("Open video %s failed" % (name))
     else:
         self._is_opened = True
     self._is_destroyed = False
     resource_list.register(self)
Example #5
0
 def __init__(self, id, fps=20, size=(1280, 720)):
     self._id = id
     self._fps = fps
     self._width = size[0]
     self._height = size[1]
     self._size = int(self._width * self._height * 3 / 2)
     self._status = CAMERA_CLOSED
     if CAMERA_OK == self._open():
         self._status = CAMERA_OPENED
     else:
         log_error("Open camera %d failed" % (id))
Example #6
0
 def __init__(self, id=0, fps=20, width=1280, height=720):
     self._id = id
     self._fps = fps
     self._width = width
     self._height = height
     self._size = int(self._width * self._height * 3 / 2)
     self._status = CAMERA_CLOSED
     if CAMERA_OK == self._open():
         self._status = CAMERA_OPENED
     else:
         acl_logger.log_error("Open camera %d failed" % (id))
Example #7
0
 def _get_image_format_by_suffix(self, filename):
     suffix = os.path.splitext(filename)[-1].strip().lower()
     if (suffix == ".jpg") or (suffix == ".jpeg"):
         image_format = ENCODE_FORMAT_JPEG
     elif suffix == ".png":
         image_format = ENCODE_FORMAT_PNG
     elif suffix == ".yuv":
         image_format = ENCODE_FORMAT_YUV420_SP
     else:
         acl_logger.log_error("Unsupport image format: %s " % suffix)
         image_format = ENCODE_FORMAT_UNKNOW
     return image_format
Example #8
0
    def read(self):  
        """
        Read camera data and allocate memory
        """
        frame_data = CameraOutputC()            
        ret = libatlas.ReadCameraFrame(self._id, byref(frame_data))
        if (ret != CAMERA_OK):
            acl_logger.log_error("ERROR:Read camera %d failed" % (self._id))
            return None

        return acl_image.AclImage(addressof(frame_data.data.contents),
                        self._width, self._height, self._size, MEMORY_DVPP)
Example #9
0
    def read(self):
        frame = ImageDataC()
        image = None
        ret = libatlas.ReadDecodedFrame(self._channel_id, byref(frame))
        if ret == READ_VIDEO_OK:
            image = AclImage(addressof(frame.data.contents), frame.width,
                             frame.height, frame.size, MEMORY_DVPP)
        elif ret == VIDEO_DECODE_FINISH:
            log_info("Video has been read finished")
        else:
            log_error("Read frame error: ", ret)

        return ret, image
Example #10
0
    def __init__(self, name):
        self._name = name
        self._channel_id = self._open(name)
        if self._channel_id == INVALID_CHANNEL_ID:
            self._is_opened = False
            log_error("Open video %s failed" % (name))
        else:
            self._is_opened = True

        self._width = 0
        self._height = 0
        self._fps = 0
        self._get_param()

        self._is_destroyed = False
        resource_list.register(self)
Example #11
0
    def destroy(self):
        """
        Determine the storage type and release
        """
        if (self._data is None) or (self.size == 0):
            acl_logger.log_error("Release image abnormaly, data is None")
            return

        if self._memory_type == MEMORY_DEVICE:
            acl.rt.free(self._data)
        elif self._memory_type == MEMORY_HOST:
            acl.rt.free_host(self._data)
        elif self._memory_type == MEMORY_DVPP:
            acl.media.dvpp_free(self._data)

        self._data = None
        self.size = 0
Example #12
0
    def read(self):
        """
        read decode frame and output status information
        """
        frame = ImageDataC()
        image = None
        ret = libatlas.ReadDecodedFrame(self._channel_id, byref(frame))
        if ret == READ_VIDEO_OK:
            image = acl_image.AclImage(addressof(frame.data.contents),
                                       frame.width, frame.height, frame.size,
                                       MEMORY_DVPP)
        if ret == READ_VIDEO_ERROR:
            acl_logger.log_error("Read frame error")
        elif ret == READ_VIDEO_NOFRAME:
            acl_logger.log_info("No frame to read")
        elif ret == READ_VIDEO_FINISHED:
            acl_logger.log_info("Read video finished")

        return ret, image
Example #13
0
    def _instance_by_image_file(self, image_path, width, height):
        #Judging file format according to file suffix
        self._encode_format = _get_image_format_by_suffix(image_path)
        if self._encode_format == ENCODE_FORMAT_UNKNOW:
            acl_logger.log_error("Load image %s failed" % (image_path))
            self._load_ok = False
            return

        self._data = np.fromfile(image_path, dtype=np.byte)
        self._type = IMAGE_DATA_NUMPY
        self.size = self._data.itemsize * self._data.size
        #If it is JPEG or PNG, get the size of the image by pillow
        if ((self._encode_format == ENCODE_FORMAT_JPEG)
                or (self._encode_format == ENCODE_FORMAT_PNG)):
            image = Image.open(image_path)
            self.width, self.height = image.size
        else:
            #If the picture is YUV, ask the caller to enter the width and height
            self.width = width
            self.height = height
Example #14
0
    def __init__(self,
                 image,
                 width=0,
                 height=0,
                 size=0,
                 memory_type=MEMORY_NORMAL):
        self._data = None
        self._np_array = None
        self._memory_type = memory_type
        self.width = 0
        self.height = 0
        self.size = 0
        self._encode_format = ENCODE_FORMAT_UNKNOW
        self._load_ok = True

        if isinstance(image, str):
            self._instance_by_image_file(image, width, height)
        elif isinstance(image, int):
            self._instance_by_buffer(image, width, height, size)
        else:
            acl_logger.log_error(
                "Create instance failed for unknow image data type")
Example #15
0
def StartPresenterAgent(msg_queue, server_ip, port, open_status,
                        data_respone_counter):
    agent = PresenterAgent(server_ip, port)
    ret = agent.connect_server()
    if ret:
        log_error("Connect server failed, ret =", ret)
        return

    open_status.value = datatype.STATUS_CONNECTED

    while True:
        data = msg_queue.get()
        if data is None:
            continue

        if isinstance(data, datatype.FinishMsg):
            log_info("Receive presenter agent exit notification, queue size ",
                     msg_queue.qsize())
            time.sleep(0.1)
            agent.exit()
            break

        agent.socket.send_msg(data)
        msg_name, msg_body = agent.socket.recv_msg()
        if (msg_name == None) or (msg_body == None):
            log_error("Recv invalid message, message name ", msg_name)
            continue

        if ((open_status.value == datatype.STATUS_CONNECTED)
                and pm.is_open_channel_response(msg_name)):
            log_info("Received open channel respone")
            open_status.value = datatype.STATUS_OPENED
            agent.start_heard_beat_thread()
            log_info("presenter agent change connect_status to ",
                     open_status.value)

        if ((open_status.value == datatype.STATUS_OPENED)
                and pm.is_image_frame_response(msg_name)):
            data_respone_counter.value += 1
Example #16
0
 def close(self):
     ret = libatlas.CloseVideo(self._channel_id)
     if ret != SUCCESS:
         log_error("Close %s failed" % (self._name))