-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
93 lines (86 loc) · 3.06 KB
/
Copy pathmainwindow.cpp
File metadata and controls
93 lines (86 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "mainwindow.h"
#include "ui_mainwindow.h"
using namespace cv;
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionOpen_Image_triggered()
{
//Open a Qt Dialog to get file name path.
fileName = QFileDialog::getOpenFileName(this,tr("Open File"));
//OpenCV read image to mat.
mat = cv::imread(fileName.toStdString());
//Check if the mat gets the image data.
if(!mat.empty())
{
//Change UMat colorchannel from BGR to RGB.
cv::cvtColor(mat,mat,cv::COLOR_BGR2RGB);
//Port image data from UMat to QImage.
QImage tmp(mat.data,
mat.cols,
mat.rows,
mat.step,
QImage::Format_RGB888);
//If QImage is too big, resize to fit the screen.
if(tmp.width() > ui->loadImage->width() ||
tmp.height() > ui->loadImage->height())
{
//QImage resize.
tmp = tmp.scaled(ui->loadImage->width(),
ui->loadImage->height(),
Qt::KeepAspectRatio);
}
//Put QImage on a label.
ui->loadImage->setPixmap(QPixmap::fromImage(tmp));
//Change UMat colorchannel from RGB back to BGR to get next image data.
cv::cvtColor(mat,mat,cv::COLOR_RGB2BGR);
}
}
void MainWindow::on_actionBlob_triggered()
{
if(mat.empty())
return;
// Blob test
cv::SimpleBlobDetector::Params params;
params.minDistBetweenBlobs = 50.0f;
params.filterByInertia = false;
params.filterByConvexity = true;
params.filterByColor = true;
params.blobColor = 0;
params.filterByCircularity = false;
params.filterByArea = true;
params.minArea = 1000.0f;
params.maxArea = 1000000.0f;
std::vector<cv::KeyPoint> keypoints;
//Method One
//cv::SimpleBlobDetector a(params);
//a.detect(mat, keypoints);
//Method Two
cv::Ptr<cv::FeatureDetector> blob_detector = cv::makePtr<cv::SimpleBlobDetector>(params);
blob_detector->detect(mat, keypoints);
cv::Mat frame = mat.clone();
//Two ways - Method one.
for (int i = 0; i < keypoints.size(); i++)
{
cv::circle(frame, cv::Point(keypoints[i].pt.x, keypoints[i].pt.y), 5, cv::Scalar(255, 0, 0), -1);
//std::cout << keypoints[i].size << std::endl;
}
/*
//Two ways - Method two.
cv::drawKeypoints(mat, keypoints, frame);
*/
for(auto blobIterator = keypoints.begin(); blobIterator != keypoints.end(); blobIterator++){
std::cout << "size of blob is: " << blobIterator->size << std::endl;
std::cout << "point is at: " << blobIterator->pt.x << " " << blobIterator->pt.y << std::endl;
}
cv::imshow("yeah", frame);
return;
}