1..基于opencv 差分图像二值分析的刀片缺陷检测
#include
#include
using namespace cv;
using namespace std;
string rootdir = "F:/Study/opencv/opencv-4.8.0/opencv/sources/samples/data/";
void sort_box(vector &boxes) {
int size = boxes.size();
for (int i = 0; i rects, vector &defect, Mat &tpl) {
int h = tpl.rows;
int w = tpl.cols;
int size = rects.size();
for (int i = 0; i (row, col);
if (pv == 255) {
count++;
}
}
}
// 填充一个像素宽
int mh = mask.rows + 2;
int mw = mask.cols + 2;
Mat m1 = Mat::zeros(Size服务器托管网(mw, mh), mask.type());
Rect mroi;
mroi.x = 1;
mroi.y = 1;
mroi.height = mask.rows;
mroi.width = mask.cols;
mask.copyTo(m1(mroi));服务器托管网
/*imshow("mask2", mask);
imshow("ml", m1);*/
waitKey(0);
// 轮廓分析
vector> contours;
vector hierarchy;
findContours(m1, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
bool find = false;
for (size_t t = 0; t 4.0 && (rect.y 10) {
printf("ratio : %.2f, area : %.2f n", ratio, area);
find = true;
}
}
if (count > 50 && find) {
printf("count : %d n", count);
defect.push_back(rects[i]);
}
}
}
void multiple_defects_detection(Mat &src) {
Mat tpl = imread(rootdir + "dt.png", IMREAD_GRAYSCALE);
// 图像二值化
Mat gray, binary;
cvtColor(src, gray, COLOR_BGR2GRAY);
threshold(gray, binary, 0, 255, THRESH_BINARY_INV | THRESH_OTSU);
imshow("binary", binary);
imwrite("D:/binary.png", binary);
// 定义结构元素
Mat se = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
morphologyEx(binary, binary, MORPH_OPEN, se);
// 轮廓发现
vector> contours;
vector hierarchy;
vector rects;
findContours(binary, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE);
int height = src.rows;
for (size_t t = 0; t (height / 2)) {
continue;
}
if (area defects;
detect_defect(binary, rects, defects, tpl);
// 显示检测结果
for (int i = 0; i
2.基于opencv DNN模块的UNet道路裂纹检测
#include
#include
using namespace cv;
using namespace std;
string model_dir="F:/Study/opencv/opencv-4.8.0/opencv/sources/samples/data/";
void resnet_surface_detection(Mat &image) {
String defect_labels[] = { "In","Sc","Cr","PS","RS","Pa" };
dnn::Net net = dnn::readNetFromONNX(model_dir + "surface_defect_resnet18.onnx");
Mat inputBlob = dnn::blobFromImage(image, 0.00392, Size(200, 200), Scalar(127, 127, 127), false, false);
inputBlob /= 0.5;
// 执行图像分类
Mat prob;
net.setInput(inputBlob);
prob = net.forward();
// 得到最可能分类输出
Mat probMat = prob.reshape(1, 1);
Point classNumber;
double classProb;
minMaxLoc(probMat, NULL, &classProb, NULL, &classNumber);
int classidx = classNumber.x;
printf("n current image classification : %s, possible : %.2fn", defect_labels[classidx].c_str(), classProb);
// 显示文本
putText(image, defect_labels[classidx].c_str(), Point(20, 40), FONT_HERSHEY_SIMPLEX, 1.0, Scalar(0, 0, 255), 2, 8);
imshow("基于分类的缺陷检测", image);
waitKey(0);
}
int main() {
Mat image = imread("F:/Study/opencv/opencv-4.8.0/opencv/sources/samples/data/NEU-CLS/NEU-CLS/Ps_1.bmp");
resnet_surface_detection(image);
return 0;
}
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
两要素 用户能够控制输入的内容 web应用把用户输入的内容,在没有经过过滤或者严格过滤的情况下带入到数据库中执行 分类 GET和POST 整数型,字符型,搜索型 万能密码 ’1 or 1 = 1# 1 or 1 = 1# 注释符: — (后面有空格) –+…