update .gitignore and delete unused code

This commit is contained in:
LDOUBLEV 2020-07-07 19:48:24 +08:00
parent acae8ea810
commit d466d31278
2 changed files with 41 additions and 51 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ output/
*.log
.clang-format
.clang_format.hook

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <chrono>
#include "paddle_api.h" // NOLINT
#include <chrono>
#include "crnn_process.h"
#include "db_post_process.h"
@ -22,9 +22,7 @@ using namespace paddle::lite_api; // NOLINT
using namespace std;
// fill tensor with mean and scale and trans layout: nhwc -> nchw, neon speed up
void neon_mean_scale(const float* din,
float* dout,
int size,
void neon_mean_scale(const float *din, float *dout, int size,
const std::vector<float> mean,
const std::vector<float> scale) {
if (mean.size() != 3 || scale.size() != 3) {
@ -68,8 +66,7 @@ void neon_mean_scale(const float* din,
}
// resize image to a size multiple of 32 which is required by the network
cv::Mat DetResizeImg(const cv::Mat img,
int max_size_len,
cv::Mat DetResizeImg(const cv::Mat img, int max_size_len,
std::vector<float> &ratio_hw) {
int w = img.cols;
int h = img.rows;
@ -108,11 +105,9 @@ cv::Mat DetResizeImg(const cv::Mat img,
return resize_img;
}
void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
cv::Mat img,
void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes, cv::Mat img,
std::shared_ptr<PaddlePredictor> predictor_crnn,
std::string dict_path,
std::vector<std::string>& rec_text,
std::string dict_path, std::vector<std::string> &rec_text,
std::vector<float> &rec_text_score) {
std::vector<float> mean = {0.5f, 0.5f, 0.5f};
std::vector<float> scale = {1 / 0.5f, 1 / 0.5f, 1 / 0.5f};
@ -139,8 +134,8 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
input_tensor0->Resize({1, 3, resize_img.rows, resize_img.cols});
auto *data0 = input_tensor0->mutable_data<float>();
neon_mean_scale(
dimg, data0, resize_img.rows * resize_img.cols, mean, scale);
neon_mean_scale(dimg, data0, resize_img.rows * resize_img.cols, mean,
scale);
//// Run CRNN predictor
predictor_crnn->Run();
@ -158,7 +153,8 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
pred_idx.push_back(int(rec_idx[n]));
}
if (pred_idx.size() < 1e-3) continue;
if (pred_idx.size() < 1e-3)
continue;
index += 1;
std::string pred_txt = "";
@ -198,9 +194,8 @@ void RunRecModel(std::vector<std::vector<std::vector<int>>> boxes,
}
}
std::vector<std::vector<std::vector<int>>> RunDetModel(
std::shared_ptr<PaddlePredictor> predictor,
cv::Mat img,
std::vector<std::vector<std::vector<int>>>
RunDetModel(std::shared_ptr<PaddlePredictor> predictor, cv::Mat img,
std::map<std::string, double> Config) {
// Read img
int max_side_len = int(Config["max_side_len"]);
@ -232,12 +227,6 @@ std::vector<std::vector<std::vector<int>>> RunDetModel(
auto *outptr = output_tensor->data<float>();
auto shape_out = output_tensor->shape();
int64_t out_numl = 1;
double sum = 0;
for (auto i : shape_out) {
out_numl *= i;
}
// Save output
float pred[shape_out[2]][shape_out[3]];
unsigned char cbuf[shape_out[2]][shape_out[3]];
@ -289,16 +278,16 @@ cv::Mat Visualization(cv::Mat srcimg,
cv::polylines(img_vis, ppt, npt, 1, 1, CV_RGB(0, 255, 0), 2, 8, 0);
}
cv::imwrite("./imgs/vis.jpg", img_vis);
std::cout << "The detection visualized image saved in ./imgs/vis.jpg"
<< std::endl;
cv::imwrite("./vis.jpg", img_vis);
std::cout << "The detection visualized image saved in ./vis.jpg" << std::endl;
return img_vis;
}
std::vector<std::string> split(const std::string &str,
const std::string &delim) {
std::vector<std::string> res;
if ("" == str) return res;
if ("" == str)
return res;
char *strs = new char[str.length() + 1];
std::strcpy(strs, str.c_str());
@ -350,8 +339,8 @@ int main(int argc, char** argv) {
std::vector<std::string> rec_text;
std::vector<float> rec_text_score;
RunRecModel(
boxes, srcimg, rec_predictor, dict_path, rec_text, rec_text_score);
RunRecModel(boxes, srcimg, rec_predictor, dict_path, rec_text,
rec_text_score);
auto end = std::chrono::system_clock::now();
auto duration =