| 1 | |
| 2 | ### image roi crop + convert to ncnn::Mat |
| 3 | |
| 4 | ``` |
| 5 | +--------------+ |
| 6 | | y | /-------/ |
| 7 | | x +-------+ | +-------+| |
| 8 | | | roih |im_h => | roih |
| 9 | | +-roiw--+ | +-roiw--+/ |
| 10 | | | |
| 11 | +-----im_w-----+ |
| 12 | ``` |
| 13 | ```cpp |
| 14 | ncnn::Mat in = ncnn::Mat::from_pixels_roi(im.data, ncnn::Mat::PIXEL_RGB, im_w, im_h, x, y, roiw, roih); |
| 15 | ``` |
| 16 | For Android Application, it is : |
| 17 | ```cpp |
| 18 | ncnn::Mat in = ncnn::Mat::from_android_bitmap_roi(env, image, ncnn::Mat::PIXEL_RGBA2RGB, x, y, roiw, roih); |
| 19 | ``` |
| 20 | |
| 21 | ### image roi crop + resize + convert to ncnn::Mat |
| 22 | |
| 23 | ``` |
| 24 | +--------------+ |
| 25 | | y | /----/ |
| 26 | | x +-------+ | +----+| |
| 27 | | | roih |im_h => | target_h |
| 28 | | +-roiw--+ | | || |
| 29 | | | +----+/ |
| 30 | +-----im_w-----+ target_w |
| 31 | ``` |
| 32 | ```cpp |
| 33 | ncnn::Mat in = ncnn::Mat::from_pixels_roi_resize(im.data, ncnn::Mat::PIXEL_RGB, im_w, im_h, x, y, roiw, roih, target_w, target_h); |
| 34 | ``` |
| 35 | For Android Application, it is : |
| 36 | ```cpp |
| 37 | ncnn::Mat in = ncnn::Mat::from_android_bitmap_roi_resize(env, image, ncnn::Mat::PIXEL_RGBA2RGB, x, y, roiw, roih, target_w, target_h); |
| 38 | ``` |
| 39 | |
| 40 | ### ncnn::Mat export image + offset paste |
| 41 | |
| 42 | ``` |
| 43 | +--------------+ |
| 44 | /-------/ | y | |
| 45 | +-------+| | x +-------+ | |
| 46 | | h| => | | h |im_h |
| 47 | +---w---+/ | +---w---+ | |
| 48 | | | |
| 49 | +-----im_w-----+ |
| 50 | ``` |
| 51 | ```cpp |
| 52 | const unsigned char* data = im.data + (y * im_w + x) * 3; |
| 53 | out.to_pixels(data, ncnn::Mat::PIXEL_RGB, im_w * 3); |
| 54 | ``` |
| 55 | |
| 56 | ### ncnn::Mat export image + resize + roi paste |
| 57 | |
| 58 | ``` |
| 59 | +--------------+ |
| 60 | /----/ | y | |
| 61 | +----+| | x +-------+ | |
| 62 | | h| => | | roih|im_h |
| 63 | | || | +-roiw--+ | |
| 64 | +-w--+/ | | |
| 65 | +-----im_w-----+ |
| 66 | ``` |
| 67 | ```cpp |
| 68 | const unsigned char* data = im.data + (y * im_w + x) * 3; |
| 69 | out.to_pixels_resize(data, ncnn::Mat::PIXEL_RGB, roiw, roih, im_w * 3); |
| 70 | ``` |
| 71 | |
| 72 | ### image roi crop + resize |
| 73 | ``` |
| 74 | +--------------+ |
| 75 | | y | |
| 76 | | x +-------+ | +----+ |
| 77 | | | roih|im_h => | target_h |
| 78 | | +-roiw--+ | | | |
| 79 | | | +----+ |
| 80 | +-----im_w-----+ target_w |
| 81 | ``` |
| 82 | ```cpp |
| 83 | const unsigned char* data = im.data + (y * im_w + x) * 3; |
| 84 | ncnn::resize_bilinear_c3(data, roiw, roih, im_w * 3, outdata, target_w, target_h, target_w * 3); |
| 85 | ``` |
| 86 | |
| 87 | ### image resize + offset paste |
| 88 | ``` |
| 89 | +--------------+ |
| 90 | | y | |
| 91 | +----+ | x +-------+ | |
| 92 | | h => | | roih |im_h |
| 93 | | | | +-roiw--+ | |
| 94 | +-w--+ | | |
| 95 | +-----im_w-----+ |
| 96 | ``` |
| 97 | ```cpp |
| 98 | unsigned char* outdata = im.data + (y * im_w + x) * 3; |
| 99 | ncnn::resize_bilinear_c3(data, w, h, w * 3, outdata, roiw, roih, im_w * 3); |
| 100 | ``` |
| 101 | |
| 102 | ### image roi crop + resize + roi paste |
| 103 | ``` |
| 104 | +--------------+ +-----------------+ |
| 105 | | y | | roiy | |
| 106 | | x +-------+ | |roix----------+ | |
| 107 | | | h |im_h => | | target_h|outim_h |
| 108 | | +---w---+ | | | | | |
| 109 | | | | +-target_w-+ | |
| 110 | +-----im_w-----+ +-----outim_w-----+ |
| 111 | ``` |
| 112 | ```cpp |
| 113 | const unsigned char* data = im.data + (y * im_w + x) * 3; |
| 114 | unsigned char* outdata = outim.data + (roiy * outim_w + roix) * 3; |
| 115 | ncnn::resize_bilinear_c3(data, w, h, im_w * 3, outdata, target_w, target_h, outim_w * 3); |
| 116 | ``` |
| 117 | |
| 118 | ### image roi crop + rotate |
| 119 | ``` |
| 120 | +--------------+ |
| 121 | | y | |
| 122 | | x +-------+ | +---+ |
| 123 | | | < < h |im_h => | ^ |w |
| 124 | | +---w---+ | | ^ | |
| 125 | | | +---+ |
| 126 | +-----im_w-----+ h |
| 127 | ``` |
| 128 | ```cpp |
| 129 | const unsigned char* data = im.data + (y * im_w + x) * 3; |
| 130 | ncnn::kanna_rotate_c3(data, w, h, im_w * 3, outdata, h, w, h * 3, 6); |
| 131 | ``` |
| 132 | |
| 133 | ### image rotate + offset paste |
| 134 | ``` |
| 135 | +--------------+ |
| 136 | | y | |
| 137 | +---+ | x +-------+ | |
| 138 | | ^ |h => | | < < w |im_h |
| 139 | | ^ | | +---h---+ | |
| 140 | +---+ | | |
| 141 | w +-----im_w-----+ |
| 142 | ``` |
| 143 | ```cpp |
| 144 | unsigned char* outdata = im.data + (y * im_w + x) * 3; |
| 145 | ncnn::kanna_rotate_c3(data, w, h, w * 3, outdata, h, w, im_w * 3, 7); |
| 146 | ``` |
| 147 | |
| 148 | ### image roi crop + rotate + roi paste |
| 149 | ``` |
| 150 | +--------------+ +-----------------+ |
| 151 | | y | | roiy | |
| 152 | | x +-------+ | | roix +---+ | |
| 153 | | | < < h |im_h => | | ^ w |outim_h |
| 154 | | +---w---+ | | | ^ | | |
| 155 | | | | +-h-+ | |
| 156 | +-----im_w-----+ +-----outim_w-----+ |
| 157 | ``` |
| 158 | ```cpp |
| 159 | const unsigned char* data = im.data + (y * im_w + x) * 3; |
| 160 | unsigned char* outdata = outim.data + (roiy * outim_w + roix) * 3; |
| 161 | ncnn::kanna_rotate_c3(data, w, h, im_w * 3, outdata, h, w, outim_w * 3, 6); |
| 162 | ``` |