You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
![]()
3 years ago
|
//
|
||
|
// Created by UnknownObject on 2022/11/4.
|
||
|
// Copyright (c) 2022 UnknownNetworkService. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#include "ocr_text.h"
|
||
|
|
||
|
bool OCRSupport::PixelCheck(const cv::Vec3b &pixel)
|
||
|
{
|
||
|
if (pixel[0] <= limit)
|
||
|
if (pixel[1] <= limit)
|
||
|
if (pixel[2] <= limit)
|
||
|
return true;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
cv::Mat OCRSupport::ConvertImage(const cv::Mat &img)
|
||
|
{
|
||
|
cv::Mat result(img.size(), img.type());
|
||
|
for (int r = 0; r < img.rows; r++)
|
||
|
{
|
||
|
for (int c = 0; c < img.cols; c++)
|
||
|
{
|
||
|
if (PixelCheck(img.at<cv::Vec3b>(r, c)))
|
||
|
result.at<cv::Vec3b>(r, c) = cv::Vec3b(0, 0, 0);
|
||
|
else
|
||
|
result.at<cv::Vec3b>(r, c) = cv::Vec3b(255, 255, 255);
|
||
|
}
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
extern "C" JNIEXPORT
|
||
|
jstring JNICALL Java_com_uns_maincar_cpp_1interface_EnvTest_OCRTextTest(JNIEnv *env, jclass _this)
|
||
|
{
|
||
|
std::string version = "OCR Text Library Found, Version: " + std::string(OCR_TEXT_VERSION);
|
||
|
return env->NewStringUTF(version.c_str());
|
||
|
}
|
||
|
|
||
|
extern "C" JNIEXPORT
|
||
|
jobject JNICALL Java_com_uns_maincar_cpp_1interface_OCR_ProcessImage(JNIEnv* env, jclass _this, jobject image)
|
||
|
{
|
||
|
cv::Mat source;
|
||
|
OCRSupport ocr_supp;
|
||
|
BitmapToMat(env,image,source);
|
||
|
cv::Mat img = ocr_supp.ConvertImage(source);
|
||
|
jobject bmp = GenerateBitmap(env, img.cols, img.rows);
|
||
|
MatToBitmap(env, img, bmp);
|
||
|
return bmp;
|
||
|
}
|