-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisionLib.cpp
More file actions
89 lines (77 loc) · 1.67 KB
/
Copy pathVisionLib.cpp
File metadata and controls
89 lines (77 loc) · 1.67 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
#include "VisionLib.h"
#include "Viewer.h"
InstanceStore * initFeed(const char * feedPath)
{
CamFeed * feed = new CamFeed(feedPath);
if (!feed->isOpened())
{
delete feed;
return NULL;
}
return new InstanceStore(feed);
}
InstanceStore * initCamera(int camIndex)
{
CamFeed * feed = new CamFeed(camIndex);
if (!feed->isOpened())
{
delete feed;
return NULL;
}
return new InstanceStore(feed);
}
bool setThreshold(InstanceStore * store, int newThreshold)
{
if (store == NULL || newThreshold < 0 || newThreshold > 255)
return false;
else
{
store->detector->thresholdVal = newThreshold;
return true;
}
}
LineResult processFrame(InstanceStore * store)
{
if (store == NULL)
{
LineResult result;
result.isProcessed = false;
return result;
}
store->feed >> store->imageStore;
if (!store->imageStore.data)
{
LineResult result;
result.isProcessed = false;
return result;
}
store->detector->prepareImage();
store->detector->findContours();
if (store->detector->filterContours())
{
return store->detector->getContours();
}
else
{
LineResult result;
result.isProcessed = true;
result.isGood = false;
return result;
}
}
void closeCamera(InstanceStore * store)
{
if (store == NULL)
return;
delete store;
}
InstanceStore::InstanceStore(CamFeed * cam) : feed(*cam)
{
imageStore.create(240, 320, 0);
detector = new TargetDetector(imageStore);
}
InstanceStore::~InstanceStore()
{
delete detector;
delete &feed;
}