Commit 291ad43e 张士柳

1 个父辈 33393dbb
......@@ -75,7 +75,7 @@ namespace eyemLib_Sharp
throw new NotSupportedException($"{"yolo_cpp_dll.dll"} has no OpenCV support");
}
}
catch (Exception exception)
catch (Exception)
{
return null;
}
......
......@@ -775,7 +775,7 @@ namespace eyemLib_Sharp
private static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
//基于深度学习读码程序(仅支持QR、DataMatrix)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, int iBlockSize, int iRangeC, double dMinorStep = 1.0);
private static extern int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, out EyemImage tpDstImg);
//加载模型配置文件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInitNNDataCodeModel(string detectorConfigPath, string detectorModelPath, string superResolutionConfigPath, string superResolutionModelPath);
......@@ -818,6 +818,8 @@ namespace eyemLib_Sharp
setLogCallback(sld);
OnNewLogCallback += new TCallBack(EyemLib_OnNewLogCallback);
eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", "", "");
}
public static void Free()
......@@ -841,12 +843,9 @@ namespace eyemLib_Sharp
public static void eyemReadImageTool(string fileName)
{
Stopwatch sw = new Stopwatch();
sw.Restart();
EyemImage image;
EyemImage tpDstImg = new EyemImage();
//int flag = eyemImageRead("D:\\图片及统计结果\\图片及统计结果\\data\\6D551\\6D551-R014212020040601587-20200624140637.png", 0, out ucpImage);
//int flag = eyemImageRead("1.png", -1, out image);
//int flag = eyemImageReadRaw(fileName, 3072, 3072, 2, out ucpImage);
int flag = eyemImageRead(fileName, -1, out image);
if (flag != 0)
......@@ -870,7 +869,6 @@ namespace eyemLib_Sharp
//flag = eyemLibImpl(image, out tpDstImg);
flag = eyemInitNNDataCodeModel(".\\darknet\\yolov3-detect-tiny.cfg", ".\\darknet\\yolov3-detect-tiny_last.weights", "", "");
......@@ -1027,12 +1025,12 @@ namespace eyemLib_Sharp
//获取用于制作模板的图像
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
}
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//创建模板匹配模型
EyemRect tpRoi2 = new EyemRect();
......@@ -1082,7 +1080,7 @@ namespace eyemLib_Sharp
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",""
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), 0.1, "IP_LARGE_PARTS", 100, 7, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), 0.1, "IP_LOWCONTRAST_PARTS", 100, 7, ref pNumObj, out tpDstImg);
//eyemCountObjectE(image, tpRoi, fileName, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), tpModels[0], hModelID, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
......@@ -1094,10 +1092,11 @@ namespace eyemLib_Sharp
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
// bitmap.Save("D:\\ResOut\\" + file);
//}
////<解码测试
Stopwatch sw = new Stopwatch();
sw.Restart();
//<解码测试
int ipNum; EyemBarCode* tpResults;
DataCodeHandle hObject;
//int iRes = eyemDetectAndDecode(image, tpRoi, file.Replace(".png", ""), "QR_CODE|DATA_MATRIX", out hObject, out tpResults, out ipNum, false, 11, 5, 128, 256);
......@@ -1108,11 +1107,24 @@ namespace eyemLib_Sharp
//}
//hObject.Dispose();
flag = eyemDetectAndDecodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, 11, 5);
flag = eyemDetectAndDecodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
sw.Stop();
Console.WriteLine(file + "--->" + "耗时:" + sw.ElapsedMilliseconds.ToString() + ",结果:" + pNumObj);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
bitmap.Save("D:\\ResOut\\" + file);
}
for (int i = 0; i < ipNum; i++)
{
Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";角度:" + tpResults[i].dAngle.ToString("F4") + "," + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + "");
Marshal.FreeCoTaskMem(tpResults[i].hText); Marshal.FreeCoTaskMem(tpResults[i].hType);
}
hObject.Dispose();
//在关闭程序时释放
//eyemReleaseModel(ref hModelID);
//free image
......@@ -1145,7 +1157,7 @@ namespace eyemLib_Sharp
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//获取用于制作模板的图像
flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//测试插入模板
//eyemInsertModel(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
......@@ -1260,6 +1272,19 @@ namespace eyemLib_Sharp
VideoHandle hObject;
eyemVideoCapture(fileName, out hObject, out tpImages, out ipNum);
for (int i = 0; i < ipNum; i += 5)
{
EyemImage tpImage = tpImages[i];
Bitmap bitmap = eyemCvtToBitmap(tpImage);
if (bitmap != null)
{
bitmap.Save("D:\\ResOut\\" + "dyn3_" + i.ToString() + ".png");
}
}
hObject.Dispose();
return;
//信号值,用于后续处理
int[] bitSingle = new int[tpRois.Count];
......@@ -1309,49 +1334,45 @@ namespace eyemLib_Sharp
}
}
public static void eyemTest(string[] fileNames)
public static void eyemTest()
{
int iRet = 0;
EyemImage imageFormer = new EyemImage();
EyemImage imageDiff = new EyemImage();
//首次需要为图像申请内存,EyemImage之间直接用=赋值是不行的
iRet = eyemImageMalloc(1080, 1440, 4, "int8_t", out imageFormer);
iRet = eyemImageMalloc(1080, 1440, 1, "uint8_t", out imageDiff);
Stopwatch sw = new Stopwatch();
sw.Restart();
int nFrmNum = 0;
for (int i = 1; i < fileNames.Length; i++)
EyemImage image;
EyemImage tpDstImg = new EyemImage();
int flag = eyemImageRead(".\\1.png", -1, out image);
if (flag != 0)
{
EyemImage imageNext = new EyemImage();
iRet = eyemImageRead(fileNames[i], -1, out imageNext);
if (iRet != 0)
{
Console.WriteLine("读图失败!");
return;
}
//转灰度图像
eyemCvtImageColor(imageNext, ColorConversionCodes.COLOR_BGR2GRAY, ref imageNext);
Console.WriteLine("读图失败!");
return;
}
flag = eyemInitNNDataCodeModel(".\\darknet\\detect-tiny.cfg", ".\\darknet\\detect-tiny.weights", "", "");
nFrmNum++;
if (nFrmNum > 0)
{
iRet = eyemImageSub(imageNext, imageFormer, ref imageDiff);
EyemRect tpRoi = new EyemRect();
tpRoi.iXs = 0; tpRoi.iYs = 0;
tpRoi.iWidth = image.iWidth;
tpRoi.iHeight = image.iHeight;
//<解码测试
int ipNum; EyemBarCode* tpResults;
DataCodeHandle hObject;
flag = eyemDetectAndDecodeUseNN(image, tpRoi, out hObject, out tpResults, out ipNum, out tpDstImg);
hObject.Dispose();
iRet = eyemImageAbs(imageDiff, ref imageDiff);
}
//前一帧,(直接赋值是不可以的,要先对其释放,拷贝时必须具有相同类型)
eyemImageCopy(imageNext, ref imageFormer);
sw.Stop();
//释放资源
eyemImageFree(ref imageNext);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
System.Threading.Thread.Sleep(350);
if (bitmap != null)
{
bitmap.Save(".\\" + "predictions.png");
}
//释放资源
eyemImageFree(ref imageFormer);
eyemImageFree(ref imageDiff);
Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
//free image
eyemImageFree(ref tpDstImg);
eyemImageFree(ref image);
}
#region EyemImage转换成Bitmap
......@@ -1404,7 +1425,7 @@ namespace eyemLib_Sharp
{
long offsetSrc = (y * tpImage.iWidth * tpImage.iChannels);
long offsetDst = (y * pd);
Buffer.MemoryCopy((byte*)(tpImage.vpImage.ToPointer()) + offsetSrc, (byte*)(bd.Scan0.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
......
......@@ -19,18 +19,16 @@ namespace eyemLib_Sharp
//初始化
EyemLib.Init();
//EyemLib.eyemTest();
string[] fileNames = Directory.GetFiles(@"D:\批量测试图像\", "*.*", SearchOption.AllDirectories);
//for (int j = 0; j < 1; j++)
//ParallelOptions po = new ParallelOptions();
//po.MaxDegreeOfParallelism = 2;
//Parallel.ForEach(fileNames, po, fn =>
//{
// ParallelOptions po = new ParallelOptions();
// po.MaxDegreeOfParallelism = 1;
// Parallel.ForEach(fileNames, po, fn =>
// {
// EyemLib.eyemReadImageTool(fn);
// });
// Console.Write("请按任意键继续。。。");
//}
// EyemLib.eyemReadImageTool(fn);
//});
foreach (var item in fileNames)
{
......@@ -39,7 +37,7 @@ namespace eyemLib_Sharp
//for (int i = 0; i < 1; i++)
//{
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\cap5.mp4");
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\ios3.mov");
//}
//IntPtr hModelID;
......
#include "objectDetection.h"
#include "detectAndDecode2d.h"
#include "yoloWrapper.h"
#include "superScale.h"
......@@ -9,6 +9,8 @@ public:
std::vector<cv::Rect> detect(const cv::Mat& img);
std::vector<std::string> decode(const cv::Mat& img, std::vector<cv::Rect>& bboxes, std::vector<cv::Rect>& points);
std::vector<float> getScaleList(const int width, const int height);
std::shared_ptr<YoloWrapper> detector_;
......@@ -16,7 +18,6 @@ public:
std::shared_ptr<SuperScale> super_resolution_model_;
};
NNDetector::NNDetector(const std::string & detector_config_path,
const std::string & detector_model_path,
const std::string & super_resolution_prototxt_path,
......@@ -40,57 +41,87 @@ NNDetector::NNDetector(const std::string & detector_config_path,
}
}
std::vector<cv::Mat> NNDetector::getScaleMap(cv::InputArray img) {
auto scale_list = p->getScaleList(img.cols(), img.rows());
auto scaleMat = std::vector<cv::Mat>();
for (auto cur_scale : scale_list) {
cv::Mat scaled = p->super_resolution_model_->processImageScale(img.getMat(), cur_scale, true);
scaleMat.push_back(scaled);
}
return scaleMat;
}
std::vector<cv::Mat> NNDetector::detect(cv::InputArray img, std::vector<cv::Rect> &points) {
std::vector<std::string> NNDetector::detectAndDecode(cv::InputArray img, std::vector<cv::Rect> &points, std::vector<cv::Rect> &allpoints) {
CV_Assert(!img.empty());
if (img.cols() <= 20 || img.rows() <= 20) {
return std::vector<cv::Mat>();
return std::vector<std::string>();
}
cv::Mat input;
int incn = img.channels();
if (incn == 4) {
cv::cvtColor(img, input, cv::COLOR_BGRA2BGR);
}
else if (incn == 1) {
cv::cvtColor(img, input, cv::COLOR_GRAY2BGR);//只支持三通道彩色图
cv::cvtColor(img, input, cv::COLOR_GRAY2BGR);//根据配置支持三通道图像
}
else {
input = img.getMat();
}
_mtx.lock();
//识别
std::vector<cv::Rect> bboxes = p->detect(input);
//限定框,防止越界
cv::Mat candiMat;
cv::Rect limit(0, 0, input.cols, input.rows);
//因为可能不准,故box会往外扩充
std::vector<cv::Mat> candidate;
for (std::vector<cv::Rect>::iterator it = bboxes.begin(); it != bboxes.end(); ++it) {
cv::Rect bbox = (*it);
int minSize = cv::min(bbox.width, bbox.height) / 2;
candiMat = input(cv::Rect(cv::Point2i(bbox.tl().x - minSize / 2, bbox.tl().y - minSize / 2), cv::Point(bbox.br().x + minSize / 2, bbox.br().y + minSize / 2))&limit);
candidate.push_back(candiMat);
points.push_back(cv::Rect(cv::Point2i(bbox.tl().x - minSize / 2, bbox.tl().y - minSize / 2), cv::Point(bbox.br().x + minSize / 2, bbox.br().y + minSize / 2))&limit);
for (auto&bbox : bboxes) {
allpoints.push_back(bbox);
}
return candidate;
//解码
std::vector<std::string> results = p->decode(input, bboxes, points);
_mtx.unlock();
return results;
}
std::vector<cv::Rect> NNDetector::Impl::detect(const cv::Mat& img) {
cv::Mat input;
resize(img, input, cv::Size(img.cols / 2, img.rows / 2), 0, 0, cv::INTER_CUBIC);//因为训练使用缩放一半的图
return detector_->forward(img);
}
std::vector<std::string> NNDetector::Impl::decode(const cv::Mat& img, std::vector<cv::Rect>& bboxes, std::vector<cv::Rect>& points) {
if (bboxes.size() == 0) {
return std::vector<std::string>();
}
std::vector<std::string> decode_results;
//限定框,防止越界
cv::Rect limit(0, 0, img.cols, img.rows);
for (auto& bbox : bboxes) {
float padding_w = 0.1f, padding_h = 0.1f;
auto min_padding = 15;
int padx = (int)cv::max(padding_w * bbox.width, static_cast<float>(min_padding));
int pady = (int)cv::max(padding_h * bbox.height, static_cast<float>(min_padding));
int crop_x_ = cv::max(bbox.tl().x - padx, 0);
int crop_y_ = cv::max(bbox.tl().y - pady, 0);
int end_x = cv::min(bbox.br().x + padx, img.cols - 1);
int end_y = cv::min(bbox.br().y + pady, img.rows - 1);
cv::Rect crop_roi(crop_x_, crop_y_, end_x - crop_x_ + 1, end_y - crop_y_ + 1);
cv::Mat cropped_img = img(crop_roi);
//转单通道
cv::cvtColor(cropped_img, cropped_img, cv::COLOR_BGR2GRAY);
auto scale_list = getScaleList(cropped_img.cols, cropped_img.rows);
for (auto cur_scale : scale_list) {
cv::Mat scaled_img =
super_resolution_model_->processImageScale(cropped_img, cur_scale, false);
std::string result;
//解码
std::vector<cv::Point> libpoints;
auto ret = decodeImage2d(scaled_img, result, 0, libpoints);
if (ret != -1) {
//解码d存储下来
for (auto& libpoint : libpoints) {
libpoint.x = cvRound((float)libpoint.x / cur_scale);
libpoint.x += crop_roi.tl().x;
libpoint.y = cvRound((float)libpoint.y / cur_scale);
libpoint.y += crop_roi.tl().y;
}
cv::Rect br = cv::boundingRect(libpoints);
points.push_back(br);
decode_results.push_back(result);
break;
}
}
}
return decode_results;
}
std::vector<float> NNDetector::Impl::getScaleList(const int width, const int height) {
if (width < 320 || height < 320) return{ 1.0, 2.0, 0.5 };
if (width < 640 && height < 640) return{ 1.0, 0.5 };
......
#pragma once
//
// objectDetection¡¤±êÍ·
// detectAndDecode2d¡¤±êÍ·
//
#ifndef __OBJECTDETECTION_H
#define __OBJECTDETECTION_H
#ifndef __DETECTANDDECODE2D_H
#define __DETECTANDDECODE2D_H
#include "opencv2/core.hpp"
#include "libdecode.h"
class NNDetector {
public:
......@@ -15,14 +16,14 @@ public:
const std::string& super_resolution_model_path = "");
NNDetector() {};
std::vector<cv::Mat> detect(cv::InputArray img,
std::vector<cv::Rect> &points = std::vector<cv::Rect>());
std::vector<std::string> detectAndDecode(cv::InputArray img,
std::vector<cv::Rect> &points = std::vector<cv::Rect>(), std::vector<cv::Rect> &allpoints = std::vector<cv::Rect>());
std::vector<cv::Mat> getScaleMap(cv::InputArray img);
std::mutex _mtx;
protected:
class Impl;
cv::Ptr<Impl> p;
};
#endif/* __OBJECTDETECTION_H */
#endif/* __DETECTANDDECODE2D_H */
......@@ -7,31 +7,12 @@
#include "eyemLib.h"
#include "dmtx.h"
#include <zxing/common/Counted.h>
#include <zxing/Binarizer.h>
#include <zxing/MultiFormatReader.h>
#include <zxing/Result.h>
#include <zxing/ReaderException.h>
#include <zxing/common/GlobalHistogramBinarizer.h>
#include <zxing/common/HybridBinarizer.h>
#include <zxing/Exception.h>
#include <zxing/common/IllegalArgumentException.h>
#include <zxing/BinaryBitmap.h>
#include <zxing/DecodeHints.h>
#include <zxing/qrcode/QRCodeReader.h>
#include <zxing/MultiFormatReader.h>
#include <zxing/MatSource.h>
#include <zxing\oned\MultiFormatOneDReader.h>
#include <zxing\datamatrix\DataMatrixReader.h>
#include <zxing\aztec\AztecReader.h>
#include <mutex>
#include <numeric>
#include <omp.h>
#include <direct.h>
#include "objectDetection.h"
using namespace zxing;
using namespace zxing::qrcode;
#include "detectAndDecode2d.h"
std::mutex mtx;
......
......@@ -1074,6 +1074,24 @@ int eyemBinNiBlack(EyemImage tpSrcImg, EyemImage *tpDstImg, int iType, int iWinS
default:
break;
}
//输出结果
///<输出计数结果标记图像
{
tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, dst.data, _Size);
}
return FUNC_OK;
}
......
......@@ -25,36 +25,153 @@ void setSkipProcessID(int pid)
killProcessID = pid;
}
static char *get_option()
static char *get_option(int * argc, char *** argv, char * opt, char * def)
{
return NULL;
int i, j;
for (i = 0; i < (*argc - 1); i++)
if (strcmp((*argv)[i], opt) == 0)
{
char * r = (*argv)[i + 1];
for (j = i; j < (*argc - 2); j++)
(*argv)[j] = (*argv)[j + 2];
*argc -= 2;
return r;
}
return def;
}
void strip_args(char *s)
{
size_t i;
size_t len = strlen(s);
size_t offset = 0;
for (i = 0; i < len; ++i) {
char c = s[i];
if (c == '\t' || c == '\n' || c == '\r' || c == 0x0d || c == 0x0a) ++offset;
else s[i - offset] = c;
}
s[len - offset] = '\0';
}
extern void run_tester(int argc, char **argv);
extern void run_count_object(int argc, char **argv);
extern void run_count_object_irregular(int argc, char **argv);
extern void run_count_object_(int argc, char **argv);
extern void run_count_object_irregular_(int argc, char **argv);
extern void run_detect_decode(int argc, char **argv);
extern void run_detect_decode_usenn(int argc, char **argv);
Logger logger;
int main(int argc, char **argv)
{
char* filename = "D:\\Matlab测试图像\\circle_plate_04.png";
cv::Mat src = cv::imread(filename, cv::IMREAD_UNCHANGED);
std::cerr << " OpenCV version: " << CV_VERSION_MAJOR << "." << CV_VERSION_MINOR << "." << CVAUX_STR(CV_VERSION_REVISION)
<< std::endl;
if (src.empty()) {
logger.t("图像文件不存在!");
std::cerr << " EyemLib version: " << "4." << FILE_VER_GET_PREFETCHED << "." << FILE_VER_GET_NEUTRAL << "." << FILE_VER_GET_LOCALISED
<< std::endl;
if (argc < 2) {
fprintf(stderr, "usage: %s <function>\n", argv[0]);
return 0;
}
int i;
for (i = 0; i < argc; ++i) {
if (!argv[i]) continue;
strip_args(argv[i]);
}
EyemRect tpRoi;
tpRoi.iXs = tpRoi.iYs = 50;
tpRoi.iWidth = src.cols; tpRoi.iHeight = src.rows;
if (0 == strcmp(argv[1], "func")) {
run_tester(argc, argv);
}
else {
EyemImage image;
image.iChannels = src.channels(); image.iDepth = 0; image.iHeight = src.rows; image.iWidth = src.cols; image.vpImage = src.data;
}
//获取结果图像
EyemImage tpDstImg;
int flag = eyemAchvTemplateImage(image, tpRoi, &tpDstImg);
return 0;
}
//加载模板
IntPtr tpModelID = NULL;
eyemInitModel("D:\\模板文件", &tpModelID);
void del_arg(int argc, char **argv, int index)
{
int i;
for (i = index; i < argc - 1; ++i) argv[i] = argv[i + 1];
argv[i] = 0;
}
int find_arg(int argc, char* argv[], char *arg)
{
int i;
for (i = 0; i < argc; ++i) {
if (!argv[i]) continue;
if (0 == strcmp(argv[i], arg)) {
del_arg(argc, argv, i);
return 1;
}
}
return 0;
}
void run_tester(int argc, char **argv)
{
char *func_name = argv[2];
if (0 == strcmp(func_name, "count_object")) run_count_object(argc, argv);
else if (0 == strcmp(func_name, "count_object_irregular")) run_count_object_irregular(argc, argv);
else if (0 == strcmp(func_name, "count_object_")) run_count_object_(argc, argv);
else if (0 == strcmp(func_name, "count_object_irregular_")) run_count_object_irregular_(argc, argv);
else if (0 == strcmp(func_name, "detect_decode")) run_detect_decode(argc, argv);
else if (0 == strcmp(func_name, "detect_decode_usenn")) run_detect_decode_usenn(argc, argv);
else printf(" There isn't such command: %s", argv[2]);
}
void run_count_object(int argc, char **argv) {
std::string filename(argv[2]);
cv::Mat src = cv::imread(filename, -1);
if (src.empty()) {
printf("file does not exist");
return;
}
}
void run_count_object_irregular(int argc, char **argv) {
std::string filename(argv[2]);
cv::Mat src = cv::imread(filename, -1);
if (src.empty()) {
printf("file does not exist");
return;
}
}
void run_count_object_(int argc, char **argv) {
std::string filename(argv[2]);
cv::Mat src = cv::imread(filename, -1);
if (src.empty()) {
printf("file does not exist");
return;
}
}
void run_count_object_irregular_(int argc, char **argv) {
std::string filename(argv[2]);
cv::Mat src = cv::imread(filename, -1);
if (src.empty()) {
printf("file does not exist");
return;
}
}
void run_detect_decode(int argc, char **argv) {
std::string filename(argv[2]);
cv::Mat src = cv::imread(filename, -1);
if (src.empty()) {
printf("file does not exist");
return;
}
}
void run_detect_decode_usenn(int argc, char **argv) {
std::string filename(argv[2]);
cv::Mat src = cv::imread(filename, -1);
if (src.empty()) {
printf("file does not exist");
return;
}
}
\ No newline at end of file
......@@ -31,7 +31,7 @@
#define FUNC_CANNOT_USE (-999) // 不可用
// 错误代码 (识别解码)
#define FUNC_FAILED_FOUND (-4) // 未识别到
#define FUNC_FAILED_DETECT (-4) // 未识别到
#define FUNC_FAILED_DECODE (-5) // 未能解码
......@@ -849,7 +849,7 @@ typedef struct {
extern "C" {
#endif
EXPORTS int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileName, const char *ccCodeType, IntPtr *hObject, EyemBarCode **tpResult, int *ipNum, bool bUseNiBlack, int iBlockSize, const int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
EXPORTS int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, int iBlockSize, int iRangeC, double dMinorStep = 1.0);
EXPORTS int eyemDetectAndDecodeUseNN(EyemImage tpImage, EyemRect tpRoi, IntPtr *hObject, EyemBarCode **hResults, int *ipNum, EyemImage *tpDstImg);
EXPORTS int eyemInitNNDataCodeModel(const char *detectorConfigPath, const char *detectorModelPath, const char *superResolutionConfigPath, const char *superResolutionModelPath);
EXPORTS bool eyemDetectAndDecodeFree(IntPtr hObject);
EXPORTS int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char *fileName, double dOffset, int iMinArea, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
......
此文件类型无法预览
......@@ -74,16 +74,17 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;D:\tbb2017_20170604oss\include;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\zxing-cpp-master\build\Debug;D:\tbb2017_20170604oss\lib\intel64\vc14;$(LibraryPath)</LibraryPath>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing\zxing;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;D:\tbb2017_20170604oss\include;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\zxing-cpp-master\build\Release;D:\tbb2017_20170604oss\lib\intel64\vc14;$(LibraryPath)</LibraryPath>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
......@@ -117,7 +118,7 @@
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libzxing-debug.lib;libdmtx.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libdmtx.lib;libdecoded.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......@@ -159,7 +160,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>libdmtx.lib;libdecode.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
......@@ -176,7 +177,7 @@
<ClInclude Include="eyemMath.h" />
<ClInclude Include="eyemMisc.h" />
<ClInclude Include="eyemSmooth.h" />
<ClInclude Include="objectDetection.h" />
<ClInclude Include="detectAndDecode2d.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="superScale.h" />
<ClInclude Include="yoloWrapper.h" />
......@@ -198,8 +199,8 @@
<ClCompile Include="eyemMath.cpp" />
<ClCompile Include="eyemMisc.cpp" />
<ClCompile Include="eyemSmooth.cpp" />
<ClCompile Include="detectAndDecode2d.cpp" />
<ClCompile Include="libopencv.cpp" />
<ClCompile Include="objectDetection.cpp" />
<ClCompile Include="superScale.cpp" />
<ClCompile Include="yoloWrapper.cpp" />
</ItemGroup>
......
......@@ -60,10 +60,10 @@
<ClInclude Include="yoloWrapper.h">
<Filter>源文件</Filter>
</ClInclude>
<ClInclude Include="objectDetection.h">
<ClInclude Include="superScale.h">
<Filter>源文件</Filter>
</ClInclude>
<ClInclude Include="superScale.h">
<ClInclude Include="detectAndDecode2d.h">
<Filter>源文件</Filter>
</ClInclude>
</ItemGroup>
......@@ -71,9 +71,6 @@
<ClCompile Include="eyemLib.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="libopencv.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="eyemMath.cpp">
<Filter>源文件</Filter>
</ClCompile>
......@@ -122,10 +119,13 @@
<ClCompile Include="yoloWrapper.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="objectDetection.cpp">
<ClCompile Include="superScale.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="superScale.cpp">
<ClCompile Include="detectAndDecode2d.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="libopencv.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
......
......@@ -12,8 +12,6 @@
#include <tbb\tbb.h>
#include "yoloWrapper.h"
constexpr double c = PI / 180.;
extern Logger logger;
......
#pragma once
//
// libdecodeͷ
//
#ifndef __LIBDECODE_LIB_H
#define __LIBDECODE_LIB_H
#include <opencv2\opencv.hpp>
#ifdef __cplusplus
extern "C" {
#endif
int decodeImage2d(cv::Mat, std::string&, int = 0, std::vector<cv::Point>& = std::vector<cv::Point>());
#ifdef __cplusplus
}
#endif
#endif/* __LIBDECODE_LIB_H */
此文件太大,无法显示。
此文件太大,无法显示。
此文件类型无法预览
......@@ -46,7 +46,7 @@ int SuperScale::superResoutionScale(const cv::Mat &src, cv::Mat &dst) {
for (int row = 0; row < prob.size[2]; row++) {
const float *prob_score = prob.ptr<float>(0, 0, row);
for (int col = 0; col < prob.size[3]; col++) {
float pixel = prob_score[col] * 255.0;
float pixel = prob_score[col] * 255.0f;
dst.at<uint8_t>(row, col) = static_cast<uint8_t>(CLIP(pixel, 0.0f, 255.0f));
}
}
......
......@@ -23,10 +23,9 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
for (int i = 0; i < outLayers.size(); i++) {
outBlobNames[i] = layerNames[outLayers[i] - 1];
}
//预处理图像
cv::Mat blob;
cv::dnn::blobFromImage(img, blob, 1 / 255., cv::Size(608, 608));
cv::dnn::blobFromImage(img, blob, 1.0 / 255.0, cv::Size(960, 960));
//为网络输入新值
net_.setInput(blob);
......@@ -68,7 +67,7 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
std::vector<int> indices;
//非极大值抑制
cv::dnn::NMSBoxes(bboxes, confidences, 0.01, 0.05, indices);
cv::dnn::NMSBoxes(bboxes, confidences, 0.01f, 0.05f, indices);
//裁剪区域
auto points = std::vector<cv::Rect>();
......@@ -77,6 +76,5 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
cv::Rect bbox = bboxes[idx] & cv::Rect(0, 0, img.cols, img.rows);
points.push_back(bbox);
}
return points;
}
\ No newline at end of file
......@@ -13,7 +13,7 @@ class YoloWrapper
{
public:
YoloWrapper() {};
~YoloWrapper() {};
~YoloWrapper() { };
int init(const std::string& config_path, const std::string& model_path);
std::vector<cv::Rect> forward(cv::Mat img);
private:
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!