예제 #1
0
 def crop_and_paste_get_roi(self, image, width, height,
                            crop_and_paste_width, crop_and_paste_height):
     """
     :image: input image
     :width: input image width 
     :height: input image height 
     :crop_and_paste_width: crop_and_paste_width
     :crop_and_paste_height: crop_and_paste_height
     :return: return AclImage
     """
     print('[Dvpp] vpc crop and paste stage:')
     input_desc = self._gen_input_pic_desc(image)
     stride_width = utils.align_up16(crop_and_paste_width)
     stride_height = utils.align_up2(crop_and_paste_height)
     out_buffer_size = utils.yuv420sp_size(stride_width, stride_height)
     out_buffer, ret = acl.media.dvpp_malloc(out_buffer_size)
     output_desc = \
         self._gen_output_pic_desc(crop_and_paste_width, crop_and_paste_height, out_buffer, out_buffer_size)
     self._crop_config = acl.media.dvpp_create_roi_config(
         0, (width >> 1 << 1) - 1, 0, (height >> 1 << 1) - 1)
     self._paste_config = acl.media.dvpp_create_roi_config(
         0, crop_and_paste_width - 1, 0, crop_and_paste_height - 1)
     ret = acl.media.dvpp_vpc_crop_and_paste_async(self._dvpp_channel_desc,
                                                   input_desc, output_desc,
                                                   self._crop_config,
                                                   self._paste_config,
                                                   self._stream)
     utils.check_ret("acl.media.dvpp_vpc_crop_and_paste_async", ret)
     ret = acl.rt.synchronize_stream(self._stream)
     utils.check_ret("acl.rt.synchronize_stream", ret)
     print('[Dvpp] vpc crop and paste stage success')
     stride_width = utils.align_up16(crop_and_paste_width)
     stride_height = utils.align_up2(crop_and_paste_height)
     return AclImage(out_buffer, stride_width, stride_height,
                     out_buffer_size, constants.MEMORY_DVPP)
예제 #2
0
파일: acl_dvpp.py 프로젝트: Ascend/canncamp
    def _stride_yuv_size(self, width, height,
                         width_align_factor=16, height_align_factor=2):
        stride_width = utils.align_up(width, width_align_factor)
        stride_height = utils.align_up(height, height_align_factor)
        stride_size = utils.yuv420sp_size(stride_width, stride_height)

        return stride_width, stride_height, stride_size
예제 #3
0
파일: acl_dvpp.py 프로젝트: Ascend/canncamp
    def jpegd(self, image):
        """
        jepg image to yuv image
        """
        # Create conversion output image desc
        output_desc, out_buffer = self._gen_jpegd_out_pic_desc(image)
        ret = acl.media.dvpp_jpeg_decode_async(self._dvpp_channel_desc,
                                               image.data(),
                                               image.size,
                                               output_desc,
                                               self._stream)
        if ret != constants.ACL_ERROR_NONE:
            log_error("dvpp_jpeg_decode_async failed ret={}".format(ret))
            return None

        ret = acl.rt.synchronize_stream(self._stream)
        if ret != constants.ACL_ERROR_NONE:
            log_error("dvpp_jpeg_decode_async failed ret={}".format(ret))
            return None

        # Return the decoded AclImage instance
        stride_width = utils.align_up128(image.width)
        stride_height = utils.align_up16(image.height)
        stride_size = utils.yuv420sp_size(stride_width, stride_height)
        return AclImage(out_buffer, stride_width,
                        stride_height, stride_size, constants.MEMORY_DVPP)
예제 #4
0
파일: acl_dvpp.py 프로젝트: Ascend/canncamp
    def crop_and_paste(
            self,
            image,
            width,
            height,
            crop_and_paste_width,
            crop_and_paste_height):
        """
        crop_and_paste
        """
        print('[Dvpp] vpc crop and paste stage:')
        input_desc = self._gen_input_pic_desc(image)
        stride_width = utils.align_up16(crop_and_paste_width)
        stride_height = utils.align_up2(crop_and_paste_height)
        out_buffer_size = utils.yuv420sp_size(stride_width, stride_height)
        out_buffer, ret = acl.media.dvpp_malloc(out_buffer_size)
        output_desc = self._gen_output_pic_desc(
            crop_and_paste_width,
            crop_and_paste_height,
            out_buffer,
            out_buffer_size)
        self._crop_config = acl.media.dvpp_create_roi_config(
            0, (width >> 1 << 1) - 1, 0, (height >> 1 << 1) - 1)
        # set crop area:
        rx = float(width) / float(crop_and_paste_width)
        ry = float(height) / float(crop_and_paste_height)
        if rx > ry:
            dx = 0
            r = rx
            dy = int((crop_and_paste_height - height / r) / 2)
        else:
            dy = 0
            r = ry
            dx = int((crop_and_paste_width - width / r) / 2)
        pasteRightOffset = int(crop_and_paste_width - 2 * dx)
        pasteBottomOffset = int(crop_and_paste_height - 2 * dy)
        if (pasteRightOffset % 2) == 0:
            pasteRightOffset = pasteRightOffset - 1
        if (pasteBottomOffset % 2) == 0:
            pasteBottomOffset = pasteBottomOffset - 1
        self._paste_config = acl.media.dvpp_create_roi_config(
            0, pasteRightOffset, 0, pasteBottomOffset)
        ret = acl.media.dvpp_vpc_crop_and_paste_async(self._dvpp_channel_desc,
                                                      input_desc,
                                                      output_desc,
                                                      self._crop_config,
                                                      self._paste_config,
                                                      self._stream)
        utils.check_ret("acl.media.dvpp_vpc_crop_and_paste_async", ret)
        ret = acl.rt.synchronize_stream(self._stream)
        utils.check_ret("acl.rt.synchronize_stream", ret)
        print('[Dvpp] vpc crop and paste stage success')
        stride_width = crop_and_paste_width - 2 * dx
        stride_height = crop_and_paste_height - 2 * dy
        #stride_width = utils.align_up16(crop_and_paste_width)
        #stride_height = utils.align_up2(crop_and_paste_height)

        return AclImage(out_buffer, stride_width,
                        stride_height, out_buffer_size, constants.MEMORY_DVPP)
예제 #5
0
 def _get_jpegd_memory_size(self, image):
     if image.is_local():
         size, ret = acl.media.dvpp_jpeg_predict_dec_size( \
             image.data(), image.size, constants.PIXEL_FORMAT_YUV_SEMIPLANAR_420)
         if ret != constants.ACL_ERROR_NONE:
             log_error("Predict jpeg decode size failed, return ", ret)
             return False, 0
         return True, size
     else:
         return True, int(
             utils.yuv420sp_size(image.width, image.height) * 3)
예제 #6
0
파일: acl_dvpp.py 프로젝트: Ascend/canncamp
 def resize(self, image, resize_width, resize_height):
     """
     Scale yuvsp420 picture to specified size
     """
     # Generate input picture desc
     input_desc = self._gen_input_pic_desc(image)
     # Calculate the image size after scaling
     stride_width = utils.align_up16(resize_width)
     stride_height = utils.align_up2(resize_height)
     output_size = utils.yuv420sp_size(stride_width, stride_height)
     # Request memory for the zoomed picture
     out_buffer, ret = acl.media.dvpp_malloc(output_size)
     if ret != constants.ACL_ERROR_NONE:
         log_error("Dvpp malloc failed, error: ", ret)
         return None
     # Create output image
     output_desc = self._gen_output_pic_desc(resize_width, resize_height,
                                             out_buffer, output_size)
     if output_desc is None:
         log_error("Gen resize output desc failed")
         return None
     # Call dvpp asynchronous zoom interface to zoom pictures
     ret = acl.media.dvpp_vpc_resize_async(self._dvpp_channel_desc,
                                           input_desc,
                                           output_desc,
                                           self._resize_config,
                                           self._stream)
     if ret != constants.ACL_ERROR_NONE:
         log_error("Vpc resize async failed, error: ", ret)
         return None
     # Wait for the zoom operation to complete
     ret = acl.rt.synchronize_stream(self._stream)
     if ret != constants.ACL_ERROR_NONE:
         log_error("Resize synchronize stream failed, error: ", ret)
         return None
     # Release the resources requested for scaling
     acl.media.dvpp_destroy_pic_desc(input_desc)
     acl.media.dvpp_destroy_pic_desc(output_desc)
     return AclImage(out_buffer, stride_width,
                     stride_height, output_size, constants.MEMORY_DVPP)