加入其他几种特征,主要是对比度有用

main
wangchunlin 4 years ago
parent 358397d204
commit 827e221f16

@ -40,7 +40,7 @@ endif (USE_CROSS)
project (ImageDetect) project (ImageDetect)
# The version number. # The version number.
set (ImageDetect_VERSION_MAJOR 5) set (ImageDetect_VERSION_MAJOR 6)
set (ImageDetect_VERSION_MINOR 0) set (ImageDetect_VERSION_MINOR 0)
# configure a header file to pass some of the CMake settings # configure a header file to pass some of the CMake settings
# to the source code # to the source code

@ -57,12 +57,84 @@ void detect_saturation(cv::Mat input_img, float& satu)
satu = mean.val[0]; satu = mean.val[0];
} }
void detect_graydiff(cv::Mat img, float& CON, float& ASM, float& ENT, float& MEAN)
{
Mat mi;
int row = img.rows;
int col = img.cols;
//CON=i*i*P(I)
//计算i
mi.create(row, col, img.type());
for (int i = 0; i < row-1; i++)
for (int j = 0; j < col; j++)
{
//cout << "BEF" << int(img.ptr<uchar>(i)[j]) << endl;
mi.at<Vec3b>(i, j) = img.at<Vec3b>(i + 1, j) - img.at<Vec3b>(i, j);
//cout << "IMF:" << int(mi.ptr<uchar>(i)[j]) << endl;
}
//计算p(I) 差值的概率
int new_cols = mi.cols;
int new_rows = mi.rows;
int gray[256] = { 0 };
double gray_prob[256] = { 0 };
int num = 0;// 像素的总个数
//统计直方图各个像素灰度值
for (int i = 0; i < mi.rows; i++)
{
uchar *p = mi.ptr<uchar>(i);
for (int j = 0; j < mi.cols; j++)
{
int value = p[j];
gray[value]++;
num++;
}
}
//计算直方图概率分布
for (int i = 0; i < 256; i++)
{
gray_prob[i] = ((double)gray[i] / num);
}
CON = 0.0;
ASM = 0.0;
ENT = 0.0;
MEAN = 0.0;
double v = 1.0/ 255.0;
for (int i = 0; i <= 255; i++)
{
CON += i*i*gray_prob[i];//计算CON
ASM += gray_prob[i] * gray_prob[i];//计算角度方向二阶矩
if (gray_prob[i]!=0)
ENT += (0-gray_prob[i] * log10(gray_prob[i]));//计算熵
MEAN += v*i*gray_prob[i];//计算平均值
}
return;
}
void detect_definition(cv::Mat input_img, float& sb, float& lap, float& dev)
{
Mat imgGray, imgSobel, imgLap, imgDev, meanValueImage;
cvtColor(input_img, imgGray, CV_BGR2GRAY);
Sobel(imgGray, imgSobel, CV_16U, 1, 1);
Laplacian(imgGray, imgLap, CV_16U);
meanStdDev(imgGray,meanValueImage,imgDev);
sb = mean(imgSobel)[0];
lap = mean(imgLap)[0];
dev = mean(imgDev)[0];
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Mat img = imread(argv[1]); Mat img = imread(argv[1]);
float cast, da, satu; float cast, da, satu, CON, ASM, ENT, MEAN, sb, lap, dev;
detect_brightness(img, cast, da); Mat img_brightness = img.clone();
detect_saturation(img, satu); detect_brightness(img_brightness, cast, da);
cout<<cast<<"||"<<da<<"||"<<satu; Mat img_saturation = img.clone();
detect_saturation(img_saturation, satu);
Mat img_graydiff = img.clone();
detect_graydiff(img_graydiff, CON, ASM, ENT, MEAN);
Mat img_definition = img.clone();
detect_definition(img_definition, sb, lap, dev);
cout<<cast<<"||"<<da<<"||"<<satu<<"||"<<CON<<"||"<<ASM<<"||"<<ENT<<"||"<<MEAN<<"||"<<sb<<"||"<<lap<<"||"<<dev;
return 0; return 0;
} }

@ -61,8 +61,15 @@ def upload(request):
cast = result[1].split("||")[0] cast = result[1].split("||")[0]
da = result[1].split("||")[1] da = result[1].split("||")[1]
satu = result[1].split("||")[2] satu = result[1].split("||")[2]
CON = result[1].split("||")[3]
ASM = result[1].split("||")[4]
ENT = result[1].split("||")[5]
MEAN = result[1].split("||")[6]
sb = result[1].split("||")[7]
lap = result[1].split("||")[8]
dev = result[1].split("||")[9]
print(cast, da, satu) print(cast, da, satu)
mesg = "颜色分布(0-1合理):{}&nbsp;&nbsp;&nbsp;分布方差(负数偏暗):{}&nbsp;&nbsp;&nbsp;色彩饱和度(零为补光):{}".format(cast, da, satu) mesg = "颜色分布(0-1合理):{}&nbsp;&nbsp;&nbsp;分布方差(负数偏暗):{}&nbsp;&nbsp;&nbsp;色彩饱和度(零为补光):{}<br/>对比度:{}&nbsp;&nbsp;&nbsp;角度方向二阶矩:{}&nbsp;&nbsp;&nbsp;熵:{}&nbsp;&nbsp;&nbsp;平均值:{}&nbsp;&nbsp;&nbsp;Sobel:{}&nbsp;&nbsp;&nbsp;Lap:{}&nbsp;&nbsp;&nbsp;dev:{}".format(cast, da, satu, CON, ASM, ENT, MEAN,sb,lap,dev)
if(int(m_class)==1): if(int(m_class)==1):
if(int(m_model)==1): #小模型 if(int(m_model)==1): #小模型
RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected"))
@ -103,8 +110,15 @@ def dlurl(request):
cast = result[1].split("||")[0] cast = result[1].split("||")[0]
da = result[1].split("||")[1] da = result[1].split("||")[1]
satu = result[1].split("||")[2] satu = result[1].split("||")[2]
CON = result[1].split("||")[3]
ASM = result[1].split("||")[4]
ENT = result[1].split("||")[5]
MEAN = result[1].split("||")[6]
sb = result[1].split("||")[7]
lap = result[1].split("||")[8]
dev = result[1].split("||")[9]
print(cast, da, satu) print(cast, da, satu)
mesg = "颜色分布(0-1合理):{}&nbsp;&nbsp;&nbsp;分布方差(负数偏暗):{}&nbsp;&nbsp;&nbsp;色彩饱和度(零为补光):{}".format(cast, da, satu) mesg = "颜色分布(0-1合理):{}&nbsp;&nbsp;&nbsp;分布方差(负数偏暗):{}&nbsp;&nbsp;&nbsp;色彩饱和度(零为补光):{}<br/>对比度:{}&nbsp;&nbsp;&nbsp;角度方向二阶矩:{}&nbsp;&nbsp;&nbsp;熵:{}&nbsp;&nbsp;&nbsp;平均值:{}&nbsp;&nbsp;&nbsp;Sobel:{}&nbsp;&nbsp;&nbsp;Lap:{}&nbsp;&nbsp;&nbsp;dev:{}".format(cast, da, satu, CON, ASM, ENT, MEAN,sb,lap,dev)
if(int(m_class)==1): if(int(m_class)==1):
if(int(m_model)==1): #小模型 if(int(m_model)==1): #小模型
RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected")) RR = DL.run(weights=(curPath+"/yolov5/v3s.pt"), source=img_path, project=(curPath+"/static/detected"))

Loading…
Cancel
Save