资源简介
C++语言开发,胶囊缺陷检测程序,里面也包括胶囊图片数据集,检测准确率高.
代码片段和文件信息
#include “opencv2/imgproc/imgproc.hpp“
#include “opencv2/highgui/highgui.hpp“
#include
#include
#include
#include
#include
using namespace cv;
using namespace std;
int kernel_size = 3;
char print_flag ;
static void help()
{
cout << “请在image窗口用鼠标分别对不同的区域(背景、体区、帽区、套合区)进行标注,然后按空格键,以完成分水岭算法,然后才能开始进行识别“ << endl;
cout << “识别结果在命令窗口给出“< }
Mat markerMask img;
Point prevPt(-1 -1);
static void onMouse(int event int x int y int flags void*)
{
if (x < 0 || x >= img.cols || y < 0 || y >= img.rows)
return;
if (event == CV_EVENT_LBUTTONUP || !(flags & CV_EVENT_FLAG_LBUTTON))
prevPt = Point(-1 -1);
else if (event == CV_EVENT_LBUTTONDOWN)
prevPt = Point(x y);
else if (event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON))
{
Point pt(x y);
if (prevPt.x < 0)
prevPt = pt;
line(markerMask prevPt pt Scalar::all(255) 5 8 0);
line(img prevPt pt Scalar::all(255) 5 8 0);
prevPt = pt;
imshow(“image“ img);
}
}
int main(int argc char** argv)
{
char* filename = argc >= 2 ? argv[1] : (char*)“D://flaw2.BMP“;
Mat img0 = imread(filename 1) imgGray;
ofstream outfile;
outfile.open(“myfile.txt“);
print_flag = 0;
if (img0.empty())
{
cout << “Couldn‘g open image “ << filename << “\n“;
return 0;
}
help();
namedWindow(“image“ 1);
namedWindow(“markerMask“ 1);
//Canny
Mat src_gray src_canny src_blur;
cvtColor(img0 src_gray CV_BGR2GRAY);
blur(src_gray src_blur Size(3 3));
imshow(“Blur“ src_blur);
Canny(src_blur src_canny 25 80 kernel_size);
imshow(“Canny“src_canny);
//Hough
Mat src_hough;
char warp_flag = 0;
img0.copyTo(src_hough);
vector lines;
double angle_sum=0angle_avr=0;
// last three: threshold minLinLength maxLineGap
HoughLinesP(src_canny lines 1 CV_PI / 180 30 100 10);
if (lines.size() > 0)
{
vector angle(lines.size());
for (size_t i = 0; i < lines.size(); i++)
{
Vec4i l = lines[i];
line(src_hough Point(l[0] l[1]) Point(l[2] l[3]) Scalar(0 0 255) 3 CV_AA);
angle[i] = atan2((l[1] - l[3])( l[2] - l[0]));
printf(“%d %d %d %d %f\n“ l[0]l[1]l[2]l[3]angle[i]);
angle_sum += angle[i];
}
angle_avr = angle_sum / lines.size();
angle_avr = angle_avr / CV_PI * 180;
if (angle_avr < 0)
{
angle_avr += 180;
}
printf(“avrage is %f\n“ angle_avr);
if (angle_avr==90.00)
{
printf(“no warp need\n“);
warp_flag = 0;
}
else
{
warp_flag = 1;
}
}
else
{
printf(“no warp need\n“);
warp_flag = 0;
}
imshow(“Hough“src_hough);
//仿射变换
Mat src_warp;
if (warp_flag == 1)
{
warp_flag = 0;
Mat rot_mat(2 3 CV_32FC1);
Point center = Point(img0.cols / 2 img0.rows / 2);
double scale = 1;
//-表示顺时针 +表示逆时针
rot_mat = getRotationMatrix2D(center (90 - angle_avr) scale);
warpAffine(img0 src_warp rot_mat src_warp.size
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-07-28 12:51 Capsule-defect-detection-master\
文件 4527 2017-07-03 10:26 Capsule-defect-detection-master\README.md
文件 6313 2017-07-03 10:26 Capsule-defect-detection-master\mask.jpg
文件 17635 2017-07-03 10:26 Capsule-defect-detection-master\main.cpp
文件 18046 2017-07-03 10:26 Capsule-defect-detection-master\LICENSE
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\good.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw9.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw8.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw7.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw6.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw5.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw4.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw3.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw2.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw10.bmp
文件 308278 2017-07-03 10:26 Capsule-defect-detection-master\flaw1.bmp
- 上一篇:rich dad and poor dad
- 下一篇:单表替换密码算法破解工具
相关资源
- unity语音识别Word Detection
- RISC-V 二值化 CNN 芯片加速器进行人员
- Pedestrian_detection_in_infrared_images.pdf
-
Single-Shot Refinement Neural Network for ob
- Image Analysis Classification and Change Detec
- Real-Time Collision Detection
- 基于深度学习人脸识别
-
You Only Look Once Unified Real-Time ob
ject - A Computational Approach to Edge Detection
-
解决 j-li
nk is defective问题.rar - Image Analysis Classification and Change Detec
- An Introduction to Signal Detection and Estima
-
ob
ject Detection in 20 Years A Survey总结汇 - Steven Kay信号检测与估计两卷Detection和
-
Robust Real-time ob
ject Detection 论文 整理 - [2011 IROS]People detection in RGB-D data
-
[2010 PAMI] ob
ject Detection with Discrimin - SSD_Single Shot MultiBox Detector.pdf
- Dlib各种组件
- Long Short Term Memory Networks for Anomaly De
- FaceDetection人脸识别系统源代码
- NiCad-5.0code colone detector
- Nicad-3.5 code clone detector
- Aggregate Channel Features for Multi-view Face
- Signal Detection And Estimation - Solution Man
- Context-Aware Saliency Detection论文和源代码
- crack detection
- stegdetect for windows
- A COMBINED CORNER AND EDGE DETECTOR 翻译
- MTCNN_face_detection_alignment.zip
评论
共有 条评论