13 #pragma warning(disable:4251) 14 #pragma warning(disable:4275) 15 # include <inference_engine.hpp> 16 # include <ie_iextension.h> 18 # include <ext_list.hpp> 22 #include <opencv2/opencv.hpp> 33 void matU8ToBlob(
const cv::Mat& orig_image, InferenceEngine::Blob::Ptr& blob,
int batchIndex = 0 )
35 InferenceEngine::SizeVector blobSize = blob->getTensorDesc().getDims();
36 const int width = int( blobSize[3] );
37 const int height = int( blobSize[2] );
39 T* blob_data = blob->buffer().as<
T*>();
41 cv::Mat resized_image( orig_image );
42 if( static_cast<int>(width) != orig_image.size().width ||
43 static_cast<int>(
height) != orig_image.size().height )
45 cv::resize( orig_image, resized_image, cv::Size( width, height ) );
48 size_t batchOffset = batchIndex * width * height *
channels;
56 blob_data[batchOffset +
h * width +
w] = resized_image.at<uchar>(
h,
w );
60 else if( channels == 3 )
68 blob_data[batchOffset +
c * width * height +
h * width +
w] =
69 resized_image.at<cv::Vec3b>(
h,
w )[
c];
76 THROW_IE_EXCEPTION <<
"Unsupported number of channels";
85 static InferenceEngine::Blob::Ptr
wrapMat2Blob(
const cv::Mat &mat )
88 size_t height = mat.size().height;
89 size_t width = mat.size().width;
91 size_t strideH = mat.step.buf[0];
92 size_t strideW = mat.step.buf[1];
95 strideW == channels &&
96 strideH == channels *
width;
98 if( !is_dense ) THROW_IE_EXCEPTION
99 <<
"Doesn't support conversion from not dense cv::Mat";
101 InferenceEngine::TensorDesc tDesc( InferenceEngine::Precision::U8,
103 InferenceEngine::Layout::NHWC );
105 return InferenceEngine::make_shared_blob<uint8_t>( tDesc, mat.data );
114 auto pos = filepath.rfind(
'.' );
115 if(
pos == std::string::npos )
117 return filepath.substr( 0,
pos );
127 cv::cvtColor( src, tmp, cv::COLOR_RGB2GRAY );
128 cv::Scalar mean = cv::mean( tmp );
130 return static_cast<float>(mean[0]);
138 std::vector< std::string > labels;
139 std::ifstream inputFile( filename );
140 std::copy( std::istream_iterator< std::string >( inputFile ),
141 std::istream_iterator< std::string >(),
142 std::back_inserter( labels ) );
156 float enlarge_coefficient = 1,
157 float dx_coefficient = 1,
158 float dy_coefficient = 1
163 int center_x = r.x + w / 2;
164 int center_y = r.y + h / 2;
167 int max_of_sizes = std::max( w, h );
168 int new_width =
static_cast<int>(enlarge_coefficient * max_of_sizes);
169 int new_height =
static_cast<int>(enlarge_coefficient * max_of_sizes);
172 int new_x = center_x -
static_cast<int>(std::floor( dx_coefficient * new_width / 2 ));
173 int new_y = center_y -
static_cast<int>(std::floor( dy_coefficient * new_height / 2 ));
175 return cv::Rect( new_x, new_y, new_width, new_height );
190 void onError(
char const * msg ) noexcept
override 192 LOG(
DEBUG) <<
"[InferenceEngine] " << msg;
float calc_intensity(const cv::Mat &src)
std::string remove_ext(const std::string &filepath)
static InferenceEngine::Blob::Ptr wrapMat2Blob(const cv::Mat &mat)
LOG(INFO)<< "Log message to default logger"
GLdouble GLdouble GLdouble w
GLsizei const GLchar *const * string
GLfloat GLfloat GLfloat GLfloat h
void onError(char const *msg) noexceptoverride
cv::Rect adjust_face_bbox(cv::Rect const &r, float enlarge_coefficient=1, float dx_coefficient=1, float dy_coefficient=1)
void matU8ToBlob(const cv::Mat &orig_image, InferenceEngine::Blob::Ptr &blob, int batchIndex=0)
GLint GLsizei GLsizei height
std::vector< std::string > read_labels(std::string const &filename)
void copy(void *dst, void const *src, size_t size)