4.18. Bmcv
Bmcv encapsulates commonly used image processing interfaces and supports hardware acceleration.
4.18.1. The constructor of Bmcv()
Init Bmcv
- Interface:
Bmcv(Handle handle);
Parameters:
handle: Handle
Specify the device handle used by Bmcv.
4.18.2. bm_image_to_tensor
Convert BMImage/BMImageArray to Tensor.
- Interface 1:
void bm_image_to_tensor(BMImage &img, Tensor &tensor); Tensor bm_image_to_tensor(BMImage &img);
Parameters 1:
image: BMImage
Input parameter. Image image that needs to be converted
tensor: Tensor
The converted Tensor.
Return 1:
tensor: Tensor
Returns the converted Tensor.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int dev_id = 0; sail::Handle handle(dev_id); string image_path = "your_image_path"; sail::Decoder decoder(image_path,false,dev_id); sail::BMImage img = decoder.read(handle); sail::Bmcv bmcv(handle); sail::Tensor tensor = bmcv.bm_image_to_tensor(img); return 0; }
- Interface 2:
def bm_image_to_tensor( image: BMImageArray, tensor) -> Tensor
Parameters 2:
image: BMImageArray
Input parameters. Image data that needs to be converted.
tensor: Tensor
Output parameters. The converted Tensor.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int dev_id = 0; sail::Handle handle(dev_id); string image_path = "your_image_path"; sail::Decoder decoder(image_path,false,dev_id); sail::BMImage img = decoder.read(handle); sail::Bmcv bmcv(handle); sail::Tensor tensor(handle,{1920,1080},BM_FLOAT32,true,true); bmcv.bm_image_to_tensor(img,tensor); return 0; }
4.18.3. tensor_to_bm_image
Convert Tensor to BMImage/BMImageArray.
- Interface 1:
void tensor_to_bm_image(Tensor &tensor, BMImage &img); BMImage tensor_to_bm_image(Tensor &tensor);
Parameters 1:
tensor: Tensor
Input parameters. The Tensor to be converted.
img : BMImage
The converted image.
Returns 1:
image : BMImage
Returns the converted image.
- Interface 2:
template<std::size_t N> void bm_image_to_tensor (BMImageArray<N> &imgs, Tensor &tensor); template<std::size_t N> Tensor bm_image_to_tensor (BMImageArray<N> &imgs);
Parameters 2:
tensor: Tensor
Input parameters. The Tensor to be converted.
img : BMImage | BMImageArray
Output parameters. Returns the converted image.
Returns 2:
image : Tensor
Return the converted tensor.
- Sample1:
#include <sail/cvwrapper.h> #include <sail/tensor.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::Tensor tensor = bmcv.bm_image_to_tensor(BMimg); sail::BMImage BMimg2 = bmcv.tensor_to_bm_image(tensor); return 0; }
- Sample2:
#include <sail/cvwrapper.h> #include <sail/tensor.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::Tensor tensor = bmcv.bm_image_to_tensor(BMimg); sail::BMImage new_img(); bmcv.tensor_to_bm_image(tensor,new_img); return 0; }
4.18.4. crop_and_resize
Crop then resize an image or an image array.
- Interface:
int crop_and_resize( BMImage &input, BMImage &output, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); BMImage crop_and_resize( BMImage &input, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> int crop_and_resize( BMImageArray<N> &input, BMImageArray<N> &output, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> BMImageArray<N> crop_and_resize( BMImageArray<N> &input, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
output : BMImage | BMImageArray
Processed image or image array.
crop_x0 : int
The starting point of the cropping window on the x-axis.
crop_y0 : int
The starting point of the cropping window on the y-axis.
crop_w : int
The width of the crop window.
crop_h : int
The height of the crop window.
resize_w : int
The target width for image resize.
resize_h : int
The target height for image resize.
resize_alg : bmcv_resize_algorithm
Interpolation algorithm for image resize, default is bmcv_resize_algorithm.BMCV_INTER_NEAREST
Returns :
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3 = bmcv.crop_and_resize(BMimg, 0, 0, BMimg.width(), BMimg.height(), 640, 640); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); ssail::BMImage BMimg3; int ret = bmcv.crop_and_resize(BMimg, BMimg3,0, 0, BMimg.width(), BMimg.height(), 640, 640); return 0; }
4.18.5. crop
Crop the image.
- Interface:
int crop( BMImage &input, BMImage &output, int crop_x0, int crop_y0, int crop_w, int crop_h); BMImage crop( BMImage &input, int crop_x0, int crop_y0, int crop_w, int crop_h); template<std::size_t N> int crop( BMImageArray<N> &input, BMImageArray<N> &output, int crop_x0, int crop_y0, int crop_w, int crop_h); template<std::size_t N> BMImageArray<N> crop( BMImageArray<N> &input, int crop_x0, int crop_y0, int crop_w, int crop_h);
Parameters:
input : BMImage | BMImageArray
Input parameter. The image or array of images to be processed.
output : BMImage | BMImageArray
Output parameter. Processed image or image array.
crop_x0 : int
Input parameter. Start point x of the crop window.
crop_y0 : int
Input parameter. Start point y of the crop window.
crop_w : int
Input parameter. Width of the crop window.
crop_h : int
Input parameter. Height of the crop window.
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3 = bmcv.crop(BMimg,100,100,200,200); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; int ret = bmcv.crop(BMimg, BMimg3,100,100,200,200); return 0; }
4.18.6. resize
Resize the image.
- Interface:
int resize( BMImage &input, BMImage &output, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); BMImage resize( BMImage &input, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> int resize( BMImageArray<N> &input, BMImageArray<N> &output, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> BMImageArray<N> resize( BMImageArray<N> &input, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
output : BMImage | BMImageArray
Processed image or image array.
resize_w : int
The target width for image resize.
resize_h : int
The target height for image resize.
resize_alg : bmcv_resize_algorithm
Interpolation algorithm for image resize, default is bmcv_resize_algorithm.BMCV_INTER_NEAREST
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3 = bmcv.resize(BMimg,640,640); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; int ret = bmcv.resize(BMimg, BMimg3,640,640); return 0; }
4.18.7. vpp_crop_and_resize
Use VPP hardware to accelerate image cropping and resizing.
- Interface:
int vpp_crop_and_resize( BMImage &input, BMImage &output, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); BMImage vpp_crop_and_resize( BMImage &input, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> int vpp_crop_and_resize( BMImageArray<N> &input, BMImageArray<N> &output, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> BMImageArray<N> vpp_crop_and_resize( BMImageArray<N> &input, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
output : BMImage | BMImageArray
Processed image or image array.
crop_x0 : int
The starting point of the cropping window on the x-axis.
crop_y0 : int
The starting point of the cropping window on the y-axis.
crop_w : int
The width of the crop window.
crop_h : int
The height of the crop window.
resize_w : int
The target width for image resize.
resize_h : int
The target height for image resize.
resize_alg : bmcv_resize_algorithm
Interpolation algorithm for image resize, default is bmcv_resize_algorithm.BMCV_INTER_NEAREST
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3 = bmcv.vpp_crop_and_resize(BMimg,100,100,300,300,300,300); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; int ret = bmcv.vpp_crop_and_resize(BMimg, BMimg3,100,100,300,300,300,300); return 0; }
4.18.8. vpp_crop_and_resize_padding
Use VPP hardware to accelerate image cropping and resizing, and padding to the specified size.
- Interface:
int vpp_crop_and_resize_padding( BMImage &input, BMImage &output, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); BMImage vpp_crop_and_resize_padding( BMImage &input, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> int vpp_crop_and_resize_padding( BMImageArray<N> &input, BMImageArray<N> &output, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> BMImageArray<N> vpp_crop_and_resize_padding( BMImageArray<N> &input, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
output : BMImage | BMImageArray
Processed image or image array.
crop_x0 : int
The starting point of the cropping window on the x-axis.
crop_y0 : int
The starting point of the cropping window on the y-axis.
crop_w : int
The width of the crop window.
crop_h : int
The height of the crop window.
resize_w : int
The target width for image resize.
resize_h : int
The target height for image resize.
padding : PaddingAtrr
padding configuration information.
resize_alg : bmcv_resize_algorithm
Interpolation algorithm for image resize, default is bmcv_resize_algorithm.BMCV_INTER_NEAREST
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::PaddingAtrr paddingatt; paddingatt.set_stx(0); paddingatt.set_sty(0); paddingatt.set_w(640); paddingatt.set_h(640); paddingatt.set_r(114); paddingatt.set_g(114); paddingatt.set_b(114); sail::BMImage BMimg4 = bmcv.vpp_crop_and_resize_padding(BMimg, 0, 0, BMimg.width(), BMimg.height(), 640, 640, paddingatt); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; sail::PaddingAtrr paddingatt; paddingatt.set_stx(0); paddingatt.set_sty(0); paddingatt.set_w(640); paddingatt.set_h(640); paddingatt.set_r(114); paddingatt.set_g(114); paddingatt.set_b(114); int ret = bmcv.vpp_crop_and_resize_padding(BMimg,BMimg3, 0, 0, BMimg.width(), BMimg.height(), 640, 640, paddingatt); return 0; }
4.18.9. vpp_crop
Use VPP hardware to accelerate image cropping.
- Interface:
int vpp_crop( BMImage &input, BMImage &output, int crop_x0, int crop_y0, int crop_w, int crop_h); BMImage vpp_crop( BMImage &input, int crop_x0, int crop_y0, int crop_w, int crop_h); template<std::size_t N> int vpp_crop( BMImageArray<N> &input, BMImageArray<N> &output, int crop_x0, int crop_y0, int crop_w, int crop_h); template<std::size_t N> BMImageArray<N> vpp_crop( BMImageArray<N> &input, int crop_x0, int crop_y0, int crop_w, int crop_h);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
output : BMImage | BMImageArray
Processed image or image array.
crop_x0 : int
The starting point of the cropping window on the x-axis.
crop_y0 : int
The starting point of the cropping window on the y-axis.
crop_w : int
The width of the crop window.
crop_h : int
The height of the crop window.
返回值说明:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3 = bmcv.vpp_crop(BMimg,100,100,200,200); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; int ret = bmcv.vpp_crop(BMimg, BMimg3,100,100,200,200); return 0; }
4.18.10. vpp_resize
Use VPP hardware to accelerate image resize and use nearest neighbor interpolation algorithm.
- 接口形式1:
int vpp_resize( BMImage &input, BMImage &output, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); BMImage vpp_resize( BMImage &input, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> int vpp_resize( BMImageArray<N> &input, BMImageArray<N> &output, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> BMImageArray<N> vpp_resize( BMImageArray<N> &input, int resize_w, int resize_h, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
output : BMImage | BMImageArray
Processed image or image array.
resize_w : int
The target width for image resize.
resize_h : int
The target height for image resize.
resize_alg : bmcv_resize_algorithm
Interpolation algorithm for image resize, default is bmcv_resize_algorithm.BMCV_INTER_NEAREST
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3 = bmcv.vpp_resize(BMimg,100,100,200,200); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; int ret = bmcv.vpp_resize(BMimg, BMimg3,100,100,200,200); return 0; }
4.18.11. vpp_resize_padding
Use VPP hardware to accelerate image resizing and padding.
- Interface:
int vpp_resize_padding( BMImage &input, BMImage &output, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); BMImage vpp_resize_padding( BMImage &input, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> int vpp_resize_padding( BMImageArray<N> &input, BMImageArray<N> &output, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); template<std::size_t N> BMImageArray<N> vpp_resize_padding( BMImageArray<N> &input, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
resize_w : int
The target width for image resize.
resize_h : int
The target height for image resize.
padding : PaddingAtrr
The configuration information of padding.
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
resize_alg : bmcv_resize_algorithm
Interpolation algorithm for image resize, default is bmcv_resize_algorithm.BMCV_INTER_NEAREST
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::PaddingAtrr paddingatt; paddingatt.set_stx(0); paddingatt.set_sty(0); paddingatt.set_w(640); paddingatt.set_h(640); paddingatt.set_r(114); paddingatt.set_g(114); paddingatt.set_b(114); sail::BMImage BMimg4 = bmcv.vpp_resize_padding(BMimg, 0, 0, 640, 640, paddingatt); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; sail::PaddingAtrr paddingatt; paddingatt.set_stx(0); paddingatt.set_sty(0); paddingatt.set_w(640); paddingatt.set_h(640); paddingatt.set_r(114); paddingatt.set_g(114); paddingatt.set_b(114); int ret = bmcv.vpp_resize_padding(BMimg,BMimg3, 640, 640, paddingatt); return 0; }
4.18.12. warp
Perform an affine transformation on the image.
- Interface:
int warp( BMImage &input, BMImage &output, const std::pair< std::tuple<float, float, float>, std::tuple<float, float, float>> &matrix, int use_bilinear = 0, bool similar_to_opencv = false); BMImage warp( BMImage &input, const std::pair< std::tuple<float, float, float>, std::tuple<float, float, float>> &matrix, int use_bilinear = 0, bool similar_to_opencv = false); template<std::size_t N> int warp( BMImageArray<N> &input, BMImageArray<N> &output, const std::array< std::pair< std::tuple<float, float, float>, std::tuple<float, float, float>>, N> &matrix, int use_bilinear = 0, bool similar_to_opencv = false); template<std::size_t N> BMImageArray<N> warp( BMImageArray<N> &input, const std::array< std::pair< std::tuple<float, float, float>, std::tuple<float, float, float>>, N> &matrix, int use_bilinear = 0, bool similar_to_opencv = false);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
output : BMImage | BMImageArray
Processed image or image array.
- matrix: std::pair<
std::tuple<float, float, float>, std::tuple<float, float, float> >
2x3 affine transformation matrix.
use_bilinear: int
Whether to use bilinear interpolation, default to 0 using nearest neighbor interpolation, 1 being bilinear interpolation
similar_to_opencv: bool
Whether to use the interface aligning the affine transformation interface of OpenCV
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; using AffineMatrix = std::pair< std::tuple<float, float, float>, std::tuple<float, float, float>>; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); AffineMatrix rotated_matrix = std::make_pair( std::make_tuple(0.9996914396, -0.02484, 0.0f), std::make_tuple(0.02484, 0.9996914396, 0.0f) ); sail::BMImage BMimg6 = bmcv.warp(BMimg, rotated_matrix); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; using AffineMatrix = std::pair< std::tuple<float, float, float>, std::tuple<float, float, float>>; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); AffineMatrix rotated_matrix = std::make_pair( std::make_tuple(0.9996914396, -0.02484, 0.0f), std::make_tuple(0.02484, 0.9996914396, 0.0f) ); sail::BMImage BMimg6; int ret= bmcv.warp(BMimg,BMimg6, rotated_matrix); return 0; }
4.18.13. convert_to
Perform a linear transformation on the image.
- Interface:
int convert_to( BMImage &input, BMImage &output, const std::tuple< std::pair<float, float>, std::pair<float, float>, std::pair<float, float>> &alpha_beta); BMImage convert_to( BMImage &input, const std::tuple< std::pair<float, float>, std::pair<float, float>, std::pair<float, float>> &alpha_beta); template<std::size_t N> int convert_to( BMImageArray<N> &input, BMImageArray<N> &output, const std::tuple< std::pair<float, float>, std::pair<float, float>, std::pair<float, float>> &alpha_beta); template<std::size_t N> BMImageArray<N> convert_to( BMImageArray<N> &input, const std::tuple< std::pair<float, float>, std::pair<float, float>, std::pair<float, float>> &alpha_beta);
Parameters:
input : BMImage | BMImageArray
The image or array of images to be processed.
- alpha_beta: std::tuple<
std::pair<float, float>, std::pair<float, float>, std::pair<float, float> >
The coefficients of the linear transformation of the three channels ((a0, b0), (a1, b1), (a2, b2)).
output : BMImage | BMImageArray
Output parameters. Processed image or image array.
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the processed image or image array.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); std::tuple<std::pair<float, float>, std::pair<float, float>, std::pair<float, float>> alpha_beta = std::make_tuple(std::make_pair(1.0 / 255, 0), std::make_pair(1.0 / 255, 0), std::make_pair(1.0 / 255, 0)); sail::BMImage BMimg5 = bmcv.convert_to(BMimg, alpha_beta); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); std::tuple<std::pair<float, float>, std::pair<float, float>, std::pair<float, float>> alpha_beta = std::make_tuple(std::make_pair(1.0 / 255, 0), std::make_pair(1.0 / 255, 0), std::make_pair(1.0 / 255, 0)); sail::BMImage BMimg5; int ret = bmcv.convert_to(BMimg,BMimg5,alpha_beta); return 0; }
4.18.14. yuv2bgr
Convert the format of the image from YUV to BGR.
- Interface:
int yuv2bgr( BMImage &input, BMImage &output); BMImage yuv2bgr(BMImage &input);
Parameters:
input : BMImage | BMImageArray
The image to be converted.
Returns:
ret: int
Returns 0 for success, others for failure.
output : BMImage | BMImageArray
Returns the converted image.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg5 = bmcv.yuv2bgr(BMimg); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg5; int ret = bmcv.yuv2bgr(BMimg,BMimg5); return 0; }
4.18.15. rectangle
Draw a rectangular box on the image.
- Interface:
int rectangle( BMImage &image, int x0, int y0, int w, int h, const std::tuple<int, int, int> &color, int thickness=1);
Parameters:
image : BMImage
The image of the rectangle to be drawn.
x0 : int
The starting point of the rectangle on the x-axis.
y0 : int
The starting point of the rectangular box on the y-axis.
w : int
The width of the rectangular box.
h : int
The height of the rectangular box.
color : tuple
The color of the rectangle.
thickness : int
The thickness of the rectangular box lines.
Returns:
Returns 0 if the frame is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.rectangle(BMimg, 20, 20, 600, 600, std::make_tuple(0, 0, 255), 2); return 0; }
4.18.16. fillRectangle
Fill a rectangular box on the image.
- Interface:
int fillRectangle( BMImage &image, int x0, int y0, int w, int h, const std::tuple<int, int, int> &color);
Parameters:
image : BMImage
The image of the rectangle to be drawn.
x0 : int
The starting point of the rectangle on the x-axis.
y0 : int
The starting point of the rectangular box on the y-axis.
w : int
The width of the rectangular box.
h : int
The height of the rectangular box.
color : tuple
The color of the rectangle.
Returns:
Returns 0 if the frame is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.fillRectangle(BMimg, 20, 20, 600, 600, std::make_tuple(0, 0, 255)); return 0; }
4.18.17. imwrite
Save the image in a specific file.
- Interface:
int imwrite( const std::string &filename, BMImage &image);
Parameters:
file_name : string
The name of the file.
output : BMImage
The image needs to be saved.
Returns:
process_status : int
Returns 0 if the save is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.imwrite("new_3.jpg", BMimg); return 0; }
4.18.18. get_handle
Get the device handle Handle in Bmcv.
- Interface:
Handle get_handle();
Returns:
handle: Handle
The device handle Handle in Bmcv.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::Handle handle1 = bmcv.get_handle(); return 0; }
4.18.19. crop_and_resize_padding
Crop and resize the image, then padding it.
- Interface:
int vpp_crop_and_resize_padding( BMImage &input, BMImage &output, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST); BMImage vpp_crop_and_resize_padding( BMImage &input, int crop_x0, int crop_y0, int crop_w, int crop_h, int resize_w, int resize_h, PaddingAtrr &padding_in, bmcv_resize_algorithm resize_alg = BMCV_INTER_NEAREST);
Parameters:
input : BMImage
The image to be processed.
output : BMImage
The processed image.
crop_x0 : int
The starting point of the cropping window on the x-axis.
crop_y0 : int
The starting point of the cropping window on the y-axis.
crop_w : int
The width of the crop window.
crop_h : int
The height of the crop window.
resize_w : int
The target width for image resize.
resize_h : int
The target height for image resize.
padding : PaddingAtrr
The configuration information of padding.
resize_alg : bmcv_resize_algorithm
The interpolation algorithm used by resize.
Returns:
process_status : int
Returns 0 if the save is successful, otherwise returns a non-zero value.
output : BMImage
Return the processed image.
- Sample1:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::PaddingAtrr paddingatt; paddingatt.set_stx(0); paddingatt.set_sty(0); paddingatt.set_w(640); paddingatt.set_h(640); paddingatt.set_r(114); paddingatt.set_g(114); paddingatt.set_b(114); sail::BMImage BMimg4 = bmcv.crop_and_resize_padding(BMimg, 0, 0, BMimg.width(), BMimg.height(), 640, 640, paddingatt); return 0; }
- Sample2:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg3; sail::PaddingAtrr paddingatt; paddingatt.set_stx(0); paddingatt.set_sty(0); paddingatt.set_w(640); paddingatt.set_h(640); paddingatt.set_r(114); paddingatt.set_g(114); paddingatt.set_b(114); bm_image bm_img = bmcv.crop_and_resize_padding(BMimg.data(), 0, 0, BMimg.width(), BMimg.height(), 640, 640, paddingatt); return 0; }
4.18.20. rectangle_
Draw a rectangule on the image.
- Interface:
int rectangle_( const bm_image &image, int x0, int y0, int w, int h, const std::tuple<int, int, int> &color, // BGR int thickness=1);
Parameters:
image : bm_image
The image to be drwan rectangule.
x0 : int
The starting point of the rectangle on the x-axis.
y0 : int
The starting point of the rectangle on the y-axis.
w : int
The width of the rectangule.
h : int
The height of the rectangule.
color : tuple
The color of the rectangle.
thickness : int
The thickness of the rectangular box lines.
Returns:
Returns 0 if the frame is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.rectangle_(BMimg, 20, 20, 600, 600, std::make_tuple(0, 0, 255), 2); return 0; }
4.18.21. fillRectangle_
Fill a rectangule on the image.
- Interface:
int fillRectangle_( const bm_image &image, int x0, int y0, int w, int h, const std::tuple<int, int, int> &color);
Parameters:
image : bm_image
The image to be drwan rectangule.
x0 : int
The starting point of the rectangle on the x-axis.
y0 : int
The starting point of the rectangle on the y-axis.
w : int
The width of the rectangule.
h : int
The height of the rectangule.
color : tuple
The color of the rectangle.
Returns:
Returns 0 if the frame is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.fillRectangle_(BMimg.data(), 20, 20, 600, 600, std::make_tuple(0, 0, 255)); return 0; }
4.18.22. imwrite_
将图像保存在指定的文件。
- Interface:
int imwrite_( const std::string &filename, const bm_image &image);
Parameters:
file_name : string
The name of the file.
output : bm_image
The image needs to be saved.
Returns:
process_status : int
Returns 0 if the save is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.imwrite_("new_3.jpg", BMimg.data()); return 0; }
4.18.23. convert_format
Convert the image format to the format in the output and copy it to the output.
- Interface 1:
int convert_format( BMImage &input, BMImage &output );
Parameters 1:
input : BMImage
Input parameters. The image to be converted.
output : BMImage
Output parameters. Convert the image in input to the image format of output and copy it to output.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg4; int ret = bmcv.convert_format(BMimg,BMimg4); return 0; }
Interface 2:
Convert an image to the target format.
BMImage convert_format( BMImage &input, bm_image_format_ext image_format = FORMAT_BGR_PLANAR );
Parameters 2:
input : BMImage
The image to be converted.
image_format : bm_image_format_ext
The target format for conversion.
Returns 2:
output : BMImage
Returns the converted image.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg4 = bmcv.convert_format(BMimg); return 0; }
4.18.24. vpp_convert_format
Use VPP hardware to accelerate image format conversion.
- Interface 1:
int vpp_convert_format( BMImage &input, BMImage &output );
Parameters 1:
input : BMImage
Input parameters. The image to be converted.
output : BMImage
Output parameters. Convert the image in input to the image format of output and copy it to output.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg4; int ret = bmcv.vpp_convert_format(BMimg,BMimg4); return 0; }
Interface 2:
Convert an image to the target format.
BMImage vpp_convert_format( BMImage &input, bm_image_format_ext image_format = FORMAT_BGR_PLANAR );
Parameters 2:
input : BMImage
The image to be converted.
image_format : bm_image_format_ext
The target format for conversion.
Returns 2:
output : BMImage
Returns the converted image.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage BMimg4 = bmcv.vpp_convert_format(BMimg); return 0; }
4.18.25. putText
Add text to the image.
- Interface:
int putText( const BMImage &image, const std::string &text, int x, int y, const std::tuple<int, int, int> &color, // BGR float fontScale, int thickness=1 );
Parameters:
input : BMImage
The image to be processed.
text: string
Text that needs to be added.
x: int
The starting point for adding the text on the x-axis.
y: int
The starting point for adding the text on the y-axis.
color : tuple
The color of the font.
fontScale: int
The size of the font.
thickness : int
The thickness of the font.
Returns:
process_status : int
Returns 0 if processing is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.putText(BMimg, "snow person" , 20, 20, std::make_tuple(0, 0, 255), 1.4, 2); return 0; }
4.18.26. putText_
- Interface:
int putText_( const bm_image &image, const std::string &text, int x, int y, const std::tuple<int, int, int> &color, // BGR float fontScale, int thickness=1 );
Parameters:
input : bm_image
The image to be processed.
text: string
Text that needs to be added.
x: int
The starting point for adding the text on the x-axis.
y: int
The starting point for adding the text on the y-axis.
color : tuple
The color of the font.
fontScale: int
The size of the font.
thickness : int
The thickness of the font.
Returns:
process_status : int
Returns 0 if processing is successful, otherwise returns a non-zero value.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.putText_(BMimg.data(), "snow person" , 20, 20, std::make_tuple(0, 0, 255), 1.4, 2); return 0; }
4.18.27. image_add_weighted
Add two images with different weights.
- Interface 1:
int image_add_weighted( BMImage &input1, float alpha, BMImage &input2, float beta, float gamma, BMImage &output );
Parameters 1:
input0 : BMImage
Input parameters. The image 0 to be processed.
alpha : float
Input parameters. The weight alpha of the two images added together.
input1 : BMImage
Input parameters. The image 1 to be processed.
beta : float
Input parameters. The weight beta of the two images added together.
gamma : float
Input parameters. The weight gamma of the two images added together.
output: BMImage
Output parameters. The added image output = input1 * alpha + input2 * beta + gamma
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name1 = "your_image_path1"; std::string image_name2 = "your_image_path2"; sail::Decoder decoder1(image_name1, true, tpu_id); sail::Decoder decoder2(image_name2, true, tpu_id); sail::BMImage BMimg1 = decoder1.read(handle); sail::BMImage BMimg2 = decoder2.read(handle); sail::Bmcv bmcv(handle); float alpha=0.2,beta=0.5,gamma=0.8; int ret = bmcv.image_add_weighted(BMimg1,alpha,BMimg2,beta,gamma,BMimg2); return 0; }
- Interface 2:
BMImage image_add_weighted( BMImage &input1, float alpha, BMImage &input2, float beta, float gamma );
Parameters 2:
input0 : BMImage
Input parameters. The image 0 to be processed.
alpha : float
Input parameters. The weight alpha of the two images added together.
input1 : BMImage
Input parameters. The image 1 to be processed.
beta : float
Input parameters. The weight beta of the two images added together.
gamma : float
Input parameters. The weight gamma of the two images added together.
Returns 2:
output: BMImage
Return the added image output = input1 * alpha + input2 * beta + gamma
- Sample:
#include <sail/cvwrapper.h> int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name1 = "your_image_path1"; std::string image_name2 = "your_image_path2"; sail::Decoder decoder1(image_name1, true, tpu_id); sail::Decoder decoder2(image_name2, true, tpu_id); sail::BMImage BMimg1 = decoder1.read(handle); sail::BMImage BMimg2 = decoder2.read(handle); sail::Bmcv bmcv(handle); float alpha=0.2,beta=0.5,gamma=0.8; sail::BMImage img= bmcv.image_add_weighted(BMimg1,alpha,BMimg2,beta,gamma); return 0; }
4.18.28. image_copy_to
Copy data between images
- Interface:
int image_copy_to(BMImage &input, BMImage &output, int start_x = 0, int start_y = 0); template<std::size_t N> int image_copy_to(BMImageArray<N> &input, BMImageArray<N> &output, int start_x = 0, int start_y = 0);
Parameters:
input: BMImage|BMImageArray
Input parameter. The BMImage or BMImageArray to be copied.
output: BMImage|BMImageArray
Output parameter. Copied BMImage or BMImageArray
start_x: int
Input parameter. Copy to the starting point of the target image.
start_y: int
Input parameter. Copy to the starting point of the target image.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name1 = "your_image_path1"; std::string image_name2 = "your_image_path2"; sail::Decoder decoder1(image_name1, true, tpu_id); sail::Decoder decoder2(image_name2, true, tpu_id); sail::BMImage BMimg1 = decoder1.read(handle); sail::BMImage BMimg2 = decoder2.read(handle); sail::Bmcv bmcv(handle); bmcv.image_copy_to(BMimg1,BMimg2,0,0); return 0; }
4.18.29. image_copy_to_padding
Copy and padding the image data between input and output.
- Interface:
int image_copy_to_padding(BMImage &input, BMImage &output, unsigned int padding_r, unsigned int padding_g, unsigned int padding_b, int start_x = 0, int start_y = 0); template<std::size_t N> int image_copy_to_padding(BMImageArray<N> &input, BMImageArray<N> &output, unsigned int padding_r, unsigned int padding_g, unsigned int padding_b, int start_x = 0, int start_y = 0);
Parameters:
input: BMImage|BMImageArray
Input parameter. The BMImage or BMImageArray to be copied.
output: BMImage|BMImageArray
Output parameter. Copied BMImage or BMImageArray.
padding_r: int
Input parameter. The padding value of the R channel.
padding_g: int
Input parameter. The padding value of the G channel.
padding_b: int
Input parameter. The padding value of the B channel.
start_x: int
Input parameter. Copy to the starting point on x-axis of the target image.
start_y: int
Input parameter. Copy to the starting point on y-axis of the target image.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name1 = "your_image_path1"; std::string image_name2 = "your_image_path2"; sail::Decoder decoder1(image_name1, true, tpu_id); sail::Decoder decoder2(image_name2, true, tpu_id); sail::BMImage BMimg1 = decoder1.read(handle); sail::BMImage BMimg2 = decoder2.read(handle); sail::Bmcv bmcv(handle); bmcv.image_copy_to_padding(BMimg1,BMimg2,128,128,128,0,0); return 0; }
4.18.30. nms
Using Tensor Computing Processor for NMS
- Interface:
nms_proposal_t* nms( face_rect_t *input_proposal, int proposal_size, float threshold);
Parameters:
input_proposal: face_rect_t
Data starting address.
proposal_size: int
The size of the detection frame data to be processed.
threshold: float
Threshold of nms.
Returns:
result: nms_proposal_t
Returns the detection frame array after NMS.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); sail::Bmcv bmcv(handle); face_rect_t *input_proposal; int proposal_size = 100; float threshold = 0.5; nms_proposal_t* result = bmcv.nms(input_proposal, proposal_size, threshold); return 0; }
4.18.31. drawPoint
Draw points on the image.
- 接口形式:
int drawPoint( const BMImage &image, std::pair<int,int> center, std::tuple<unsigned char, unsigned char, unsigned char> color, // BGR int radius);
参数说明:
image: BMImage
Input image. Draw points directly on the BMImage as output.
center: std::pair<int,int>
The center coordinates of the point.
color: std::tuple<unsigned char, unsigned char, unsigned char>
The color of the point.
radius: int
The radius of the point.
Returns
If the point is drawn successfully, 0 is returned, otherwise a non-zero value is returned.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path1"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.drawPoint(BMimg, std::pair(320, 320), std::make_tuple(0, 255, 255), 2); return 0; }
4.18.32. drawPoint_
Draw points on the image.
- Interface:
int drawPoint_( const bm_image &image, std::pair<int,int> center, std::tuple<unsigned char, unsigned char, unsigned char> color, // BGR int radius);
Parameters:
image: bm_image
Input image. Draw points directly on the BMImage as output.
center: std::pair<int,int>
The center coordinates of the point.
color: std::tuple<unsigned char, unsigned char, unsigned char>
The color of the point.
radius: int
The radius of the point.
Returns
If the point is drawn successfully, 0 is returned, otherwise a non-zero value is returned.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); int ret = bmcv.drawPoint(BMimg.data(), std::pair(320, 320), std::make_tuple(0, 255, 255), 2); return 0; }
4.18.33. warp_perspective
Performs perspective transformation on the image.
- Interface:
BMImage warp_perspective( BMImage &input, const std::tuple< std::pair<int,int>, std::pair<int,int>, std::pair<int,int>, std::pair<int,int>> &coordinate, int output_width, int output_height, bm_image_format_ext format = FORMAT_BGR_PLANAR, bm_image_data_format_ext dtype = DATA_TYPE_EXT_1N_BYTE, int use_bilinear = 0);
Parameters:
input: BMImage
The image to be processed.
- coordinate: std::tuple<
std::pair<int,int>, std::pair<int,int>, std::pair<int,int>, std::pair<int,int> >
The original coordinates of the four vertices of the transformed area.
Such as, ((left_top.x, left_top.y), (right_top.x, right_top.y), (left_bottom.x, left_bottom.y), (right_bottom.x, right_bottom.y))
output_width: int
The width of the output image.
output_height: int
The height of the output image.
format: bm_image_format_ext
The format of the output image.
dtype: bm_image_data_format_ext
The data type of the output image.
use_bilinear: int
Whether to use bilinear interpolation.
Returns:
output: BMImage
Output the transformed image.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); std::tuple< std::pair<int, int>, std::pair<int, int>, std::pair<int, int>, std::pair<int, int> > coordinate = std::make_tuple( std::make_pair(100, 100), std::make_pair(200, 100), std::make_pair(100, 200), std::make_pair(200, 200) ) int output_width = 300; int output_height = 300; bm_image_format_ext format = FORMAT_BGR_PLANAR; bm_image_data_format_ext dtype = DATA_TYPE_EXT_1N_BYTE; int use_bilinear = 1; sail::BMImage output = bmcv.warp_perspective(BMimg,coordinate,output_width,output_height,format,dtype,use_bilinear ); return 0; }
4.18.34. get_bm_data_type
Convert ImgDtype to Dtype
- Interface:
bm_data_type_t get_bm_data_type(bm_image_data_format_ext fmt);
Parameters:
fmt: bm_image_data_format_ext
The type to be converted.
Returns:
ret: bm_data_type_t
The converted type.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); sail::Bmcv bmcv(handle); bm_data_type_t ret = bmcv.get_bm_data_type(bm_image_data_format_ext::DATA_TYPE_EXT_FLOAT32); return 0; }
4.18.35. get_bm_image_data_format
Convert Dtype to ImgDtype.
- Interface:
bm_image_data_format_ext get_bm_image_data_format(bm_data_type_t dtype);
Parameters:
dtype: bm_data_type_t
The Dtype that needs to be converted.
Returns:
ret: bm_image_data_format_ext
Returns the converted type.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); sail::Bmcv bmcv(handle); bm_image_data_format_ext ret = bmcv.get_bm_image_data_format(bm_data_type_t::BM_FLOAT32); return 0; }
4.18.36. imdecode
Load the image from memory into BMImage.
- Interface:
BMImage imdecode(const void* data_ptr, size_t data_size);
Parameters:
data_ptr: void*
The data starting address.
data_size: bytes
The data length.
Returns:
ret: BMImage
Returns the decoded image.
- Sample:
#include <sail/cvwrapper.h> int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; std::ifstream image_file(image_name, std::ios::binary); if (!image_file) { std::cout << "Error opening image file." << std::endl; return -1; } std::vector<char> image_data_bytes( (std::istreambuf_iterator<char>(image_file)), (std::istreambuf_iterator<char>()) ); image_file.close(); sail::Bmcv bmcv(handle); sail::BMImage src_img = bmcv.imdecode(image_data_bytes.data(), image_data_bytes.size()); return 0; }
4.18.37. imencode
Encode an BMimage and return the encoded data.
- Interface1:
bool Bmcv::imencode(std::string& ext, bm_image &img, std::vector<u_char>& buf)
- Interface2:
bool Bmcv::imencode(std::string& ext, BMImage &img, std::vector<u_char>& buf)
Parameters:
ext: string
Input parameter. Image encoding format, supported formats include ".jpg"
, ".png"
, etc.
image: bm_image/BMImage
Input parameter. Input bm_image/BMImage, only FORMAT_BGR_PACKED, DATA_TYPE_EXT_1N_BYTE pictures are supported.
buf: std::vector<u_char>
Output parameter. Data that is encoded and placed in system memory.
返回值说明:
ret: bool
Returns 0 if encoding is successful and 1 if encoding fails.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); std::vector<u_char> encoded_data; std::string ext = ".jpg"; bool success = bmcv.imencode(ext, BMimg, encoded_data); //bool success = bmcv.imencode(ext, BMimg.data(), encoded_data); 接口形式1:bm_image return 0; }
4.18.38. fft
Implement the Fast Fourier Transform of Tensor.
- Interface:
std::vector<Tensor> fft(bool forward, Tensor &input_real); std::vector<Tensor> fft(bool forward, Tensor &input_real, Tensor &input_imag);
Parameters:
forward: bool
Whether to perform forward migration.
input_real: Tensor
The real part of the input.
input_imag: Tensor
The imaginary part of the input.
Returns:
ret: std::vector<Tensor>
Returns the real and imaginary parts of the output.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); sail::Bmcv bmcv(handle); std::vector<int> shape = {512, 512}; sail::Tensor input_real(shape); bool forward = true; //std::vector<sail::Tensor> result_real = bmcv.fft(forward, input_real); sail::Tensor input_imag(shape); std::vector<sail::Tensor> result_complex = bmcv.fft(forward, input_real,input_imag); return 0; }
4.18.39. convert_yuv420p_to_gray
Convert pictures in YUV420P format to grayscale images.
- Interface 1:
int convert_yuv420p_to_gray(BMImage& input, BMImage& output);
Parameters 1:
input : BMImage
Input parameters. The image to be converted.
output : BMImage
Output parameters. Converted image.
Interface 2:
Convert pictures in YUV420P format to grayscale images.
int convert_yuv420p_to_gray_(bm_image& input, bm_image& output);
Parameters 2:
input : bm_image
The image to be converted.
output : bm_image
The converted image.
- Sample:
#include <sail/cvwrapper.h> using namespace std; int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path1"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); sail::BMImage img; int ret = bmcv.convert_yuv420p_to_gray(BMimg, img); return 0; }
4.18.40. polylines
Draw one or more line segments on an image, so that the function of drawing polygons can be realized, and the color and width of the line can be specified.
- Interface:
int polylines( BMImage &img, std::vector<std::vector<std::pair<int,int>>> &pts, bool isClosed, std::tuple<unsigned char, unsigned char, unsigned char> color, int thickness = 1, int shift = 0);
Parameters:
img : BMImage
Input BMImage.
pts : std::vector<std::vector<std::pair<int,int>>>
The starting point and end point coordinates of the line segment, multiple coordinate points can be entered. The upper left corner of the image is the origin, extending to the right in the x direction and extending down in the y direction.
isClosed : bool
Whether the graph is closed.
color : std::tuple<unsigned char, unsigned char, unsigned char>
The color of the line is the value of the three RGB channels.
thickness : int
The width of the lines is recommended to be even for YUV format images.
shift : int
Polygon scaling multiple. Default is not scaling. The scaling factor is(1/2)^shift。
Returns:
ret: int
returns 0 if success.
- Sample:
#include <sail/cvwrapper.h> int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); std::vector<std::vector<std::pair<int, int>>> pts = { {{100, 100}, {150, 100}, {150, 150}, {100, 150}}, {{200, 200}, {250, 200}, {250, 250}, {200, 250}} }; bool isClosed = true; int thickness = 2; std::tuple<unsigned char, unsigned char, unsigned char> color = std::make_tuple(255, 0, 0); int shift = 0; int result = bmcv.polylines(BMimg, pts, isClosed, color, thickness, shift); if (result == 0) { std::cout << "Polylines drawn successfully." << std::endl; } else { std::cout << "Failed to draw polylines." << std::endl; } return 0; }
4.18.41. mosaic
Print one or more mosaics on an image.
- Interface:
int mosaic( int mosaic_num, BMImage &img, vector<vector<int>> rects, int is_expand);
Parameters:
mosaic_num : int
Number of mosaics, length of list in rects.
img : BMImage
Input BMImage.
rects : vector<vector<int>>
Multiple Mosaic positions, the parameters in each element in the list are [Mosaic at X-axis start point, Mosaic at Y-axis start point, Mosaic width, Mosaic height].
is_expand : int
Whether to expand the column. A value of 0 means that the column is not expanded, and a value of 1 means that a macro block (8 pixels) is expanded around the original Mosaic.
Returns:
ret: int
returns 0 if success.
- Sample:
#include <sail/cvwrapper.h> int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); std::vector<std::vector<int>> rects = { {100, 100, 50, 50}, {200, 200, 60, 60} }; int mosaic_num = rects.size(); / int is_expand = 0; int result = bmcv.mosaic(mosaic_num, BMimg, rects, is_expand); if (result == 0) { std::cout << "Mosaic applied successfully." << std::endl; } else { std::.cout << "Failed to apply mosaic." << std::endl; } return 0; }
4.18.42. transpose
Transpose of image width and height.
- Interface1:
BMImage Bmcv::transpose(BMImage &src);
Parameters1:
src : BMImage
Input BMImage.
Returns2:
output: BMImage:
output BMImage.
- Interface2:
int Bmcv::transpose( BMImage &src, BMImage &dst);
Parameters2:
src : BMImage
Input BMImage.
dst : BMImage
output BMImage.
Returns2:
ret : int
returns 0 if success.
- Sample:
#include <sail/cvwrapper.h> int main() { int dev_id = 0; sail::Handle handle(dev_id); std::string image_name = "your_img.jpg"; sail::Decoder decoder(image_name, true, dev_id); sail::BMImage BMimg_input = decoder.read(handle); sail::BMImage BMimg_output; sail::Bmcv bmcv(handle); int ret = bmcv.transpose(BMimg_input,BMimg_output); if(ret != 0){ std::cout << "gaussian_blur failed" << std::endl; return -1; } bmcv.imwrite("output.jpg",BMimg_output); return 0; }
4.18.43. watermark_superpose
Implement adding multiple watermarks to images.
- 接口形式:
int Bmcv::watermark_superpose( BMImage &img, string water_name, int bitmap_type, int pitch, vector<vector<int>> rects, const std::tuple<int, int, int> &color);
参数说明:
Image: BMImage
Input image
Watername: string
Watermark file path
Bitmap_type: int
Input parameters. Watermark type, a value of 0 indicates that the watermark is an 8-bit data type (with transparency information), and a value of 1 indicates that the watermark is a 1-bit data type (without transparency information).
Pitch: int
Input parameters. The number of bytes per line in a watermark file can be understood as the width of the watermark.
Rects: vector
Input parameters. Watermark position, including the starting point and width/height of each watermark.
Color: const std:: tuple<int, int, int>
Input parameters. The color of the watermark.
Return value description:
Ret: int
Whether the return was successful
- Sample:
#include <sail/cvwrapper.h> int main() { int tpu_id = 0; sail::Handle handle(tpu_id); std::string image_name = "your_image_path"; sail::Decoder decoder(image_name, true, tpu_id); sail::BMImage BMimg = decoder.read(handle); sail::Bmcv bmcv(handle); std::string water_name = "your_watermark_path"; int bitmap_type = 0; int pitch =117; std::vector<std::vector<int>> rects = { {10, 10, 117, 79}, {200, 150, 117, 79} }; std:: vector<int> color = {128,128,128}; int result = bmcv.watermark_superpose(BMimg, water_name, bitmap_type, pitch, rects, color); if (result == 0) { std::cout << "Watermarks added successfully." << std::endl; } else { std::cout << "Failed to add watermarks." << std::endl; } return 0; }
4.18.44. gaussian_blur
This interface is used for image Gaussian filtering. Note: The previous SDK does not support BM1684X. For details about whether the current SDK supports BM1684X, check the page “BMCV API” in《Multimedia User Guide》. *
Interface1:
int gaussian_blur(
BMImage &input,
BMImage &output,
int kw,
int kh,
float sigmaX,
float sigmaY = 0.0f);
Parameters1:
input : BMImage
Input BMImage.
output : BMImage
Output BMImage.
kw : int
The size of kernel in the width direction.
kh : int
The size of kernel in the height direction.
sigmaX : float
Gaussian kernel standard deviation in the X direction.
sigmaY : float
Gaussian kernel standard deviation in the Y direction.Default is 0, which means that it is the same standard deviation as the Gaussian kernel in the X direction.
Returns1:
ret: int
returns 0 if success.
Interface2:
BMImage gaussian_blur(
BMImage &input,
int kw,
int kh,
float sigmaX,
float sigmaY = 0.0f);
Parameters2:
input : BMImage
Input BMImage.
kw : int
The size of kernel in the width direction.
kh : int
The size of kernel in the height direction.
sigmaX : float
Gaussian kernel standard deviation in the X direction.
sigmaY : float
Gaussian kernel standard deviation in the Y direction.Default is 0, which means that it is the same standard deviation as the Gaussian kernel in the X direction.
Returns2:
output : BMImage
Returns a Gaussian filtered image.
- Sample:
#include <sail/cvwrapper.h> int main() { int dev_id = 0; sail::Handle handle(dev_id); std::string image_name = "your_img.jpg"; sail::Decoder decoder(image_name, true, dev_id); sail::BMImage BMimg_input = decoder.read(handle); sail::BMImage BMimg_output; sail::Bmcv bmcv(handle); int ret = bmcv.gaussian_blur(BMimg_input,BMimg_output,3, 3, 0.1); if(ret != 0){ std::cout << "gaussian_blur failed" << std::endl; return -1; } bmcv.imwrite("output.jpg",BMimg_output); return 0; }
4.18.45. Sobel
Sobel operator for edge detection.
Note: For details about whether this operator in current SDK supports BM1684X, check the page “BMCV API” in 《Multimedia User Guide》.
- Interface1:
int Sobel( BMImage &input, BMImage &output, int dx, int dy, int ksize = 3, float scale = 1, float delta = 0);
Parameters1:
input
Input BMImage
output
Output BMImage
dx
Order of the derivative x.
dy
Order of the derivative y
ksize
ize of the extended Sobel kernel; it must be -1, 1, 3, 5, or 7. -1 means 3x3 Scharr filter will be used.
scale
Optional scale factor for the computed derivative values; by default, no scaling is applied
delta
Optional delta value that is added to the results prior to storing them in dst.
Returns1:
ret: int
returns 0 if success.
- Interface2:
BMImage Sobel( BMImage &input, int dx, int dy, int ksize = 3, float scale = 1, float delta = 0);
Parameters2:
input
Input BMImage
dx
Order of the derivative x.
dy
Order of the derivative y
ksize
ize of the extended Sobel kernel; it must be -1, 1, 3, 5, or 7. -1 means 3x3 Scharr filter will be used.
scale
Optional scale factor for the computed derivative values; by default, no scaling is applied
delta
Optional delta value that is added to the results prior to storing them in dst.
Returns2:
output: BMImage
returns porcessed BMImage.
- Sample:
#include <sail/cvwrapper.h> int main() { int dev_id = 0; sail::Handle handle(dev_id); std::string image_name = "your_img.jpg"; sail::Decoder decoder(image_name, true, dev_id); sail::BMImage BMimg_input = decoder.read(handle); sail::BMImage BMimg_output; sail::Bmcv bmcv(handle); int ret = bmcv.Sobel(BMimg_input,BMimg_output,1,1); if(ret != 0){ std::cout << "Sobel failed" << std::endl; return -1; } bmcv.imwrite("output.jpg",BMimg_output); return 0; }