-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageProcessor.cpp
More file actions
76 lines (60 loc) · 2.1 KB
/
ImageProcessor.cpp
File metadata and controls
76 lines (60 loc) · 2.1 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
#include "ImageProcessor.h"
#define AREA_MINIMUM 500
ImageProcessor::ImageProcessor() : threshold(Threshold(100, 140, 90, 255, 20, 255)) { // GREEN HSL
thresholdImage = 0;
convexHullImage = 0;
filteredImage = 0;
ParticleFilterCriteria2 criteria = {IMAQ_MT_AREA, AREA_MINIMUM, 65535, false, false};
SetParticleCriteria(criteria);
}
ImageProcessor::~ImageProcessor() {
delete thresholdImage;
delete convexHullImage;
delete filteredImage;
}
BinaryImage * ImageProcessor::Process(ColorImage * image) {
ParticleFilterCriteria2 criteria[] = { particleCriteria };
thresholdImage = image->ThresholdHSL(threshold);
convexHullImage = thresholdImage->ConvexHull(false);
filteredImage = convexHullImage->ParticleFilter(criteria, 1);
return filteredImage;
}
BinaryImage * ImageProcessor::GetThresholdImage() const {
return thresholdImage;
}
BinaryImage * ImageProcessor::GetConvexHullImage() const {
return convexHullImage;
}
BinaryImage * ImageProcessor::GetFilteredImage() const {
return filteredImage;
}
void ImageProcessor::SetThreshold(const Threshold &threshold) {
this->threshold = threshold;
}
void ImageProcessor::SetThreshold(simple_threshold threshold) {
if (threshold == GREEN) {
SetThreshold(Threshold(60, 100, 90, 255, 20, 255));
} else if (threshold == BLUE) {
SetThreshold(Threshold(150, 190, 90, 255, 100, 255));
} else {
SetThreshold(GREEN);
}
}
void ImageProcessor::SetParticleCriteria(const ParticleFilterCriteria2 &criteria) {
particleCriteria = criteria;
}
void ImageProcessor::WriteImages(const char * baseFilename) const {
size_t length = strlen(baseFilename);
char * filename = new char[length + 8];
strcpy(filename, baseFilename);
strcpy(&filename[length], "-th.bmp");
filename[length+7] = '\0';
thresholdImage->Write(filename);
strcpy(&filename[length], "-ch.bmp");
filename[length+7] = '\0';
convexHullImage->Write(filename);
strcpy(&filename[length], "-fl.bmp");
filename[length+7] = '\0';
filteredImage->Write(filename);
delete[] filename;
}