Skip to content

OpenVINO Integration into EasyOCR C++#1

Draft
avbelova wants to merge 14 commits intomainfrom
openvino-integration
Draft

OpenVINO Integration into EasyOCR C++#1
avbelova wants to merge 14 commits intomainfrom
openvino-integration

Conversation

@avbelova
Copy link
Owner

Add OpenVINO backend to the EasyOCR C++ library

@avbelova avbelova assigned avbelova and unassigned avbelova Oct 10, 2024
@avbelova
Copy link
Owner Author

@likholat please take a look

auto colorRead = (channels == 3) ? CV_32FC3 : CV_32FC1;
c.convertTo(c, colorRead, scale);

ov::Shape input_shape = { 1, size_t(c.rows), size_t(c.cols), size_t(channels) };

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use C++ style casting: static_cast<size_t>(c.rows)


ov::Tensor OpenVINOModel::convertToTensor(const cv::Mat& img, bool normalize, bool color)
{
cv::Mat c = img.clone();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this clone here?


ov::Shape input_shape = { 1, size_t(c.rows), size_t(c.cols), size_t(channels) };
ov::element::Type input_type = ov::element::f32;
ov::Tensor converted = ov::Tensor(input_type, input_shape, c.data);
Copy link

@likholat likholat Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create 2 tensors to copy data

Suggested change
ov::Tensor converted = ov::Tensor(input_type, input_shape, c.data);
ov::Tensor res = ov::Tensor(input_type, input_shape);
std::memcpy(res.data(), img.data, img.total() * img.elemSize());

@@ -0,0 +1,85 @@

#include "OpenvinoModel.h"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "OpenvinoModel.h"
#include "OpenvinoModel.hpp"

c.convertTo(c, colorRead, scale);

ov::Shape input_shape = { 1, size_t(c.rows), size_t(c.cols), size_t(channels) };
ov::element::Type input_type = ov::element::f32;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a check for input data type, something like:

Suggested change
ov::element::Type input_type = ov::element::f32;
ov::element::Type input_type;
switch (img.type()) {
case CV_32F:
precision = ov::element::f32;
break;
case CV_8U:
precision = ov::element::u8;
break;
default:
OPENVINO_THROW("Unsupported data type for image'");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants