This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tape-detector.cpp
61 lines (48 loc) · 1.92 KB
/
tape-detector.cpp
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
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include "ShapeMatcher.h"
#include "Contour.h"
#include "utils.h"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
/// Load & prep src image
Mat src, drawing;
src = imread( argv[1], 1 );
drawing = Mat::zeros(src.size(), CV_8UC3);
bool isMatch, isMatch2;
vector<Contour> contours = detectContoursColorFiltered(&src, &HSV_YELLOW,6, 25);
BackwardsLMatcher blm(NULL);
LMatcher lm(NULL);
drawContourList(&contours, &drawing);
for(int i=0; i < contours.size(); i++)
contourDrawPoints(&contours[i], &drawing);
Contour matchingContour, matchingContour2;
Rect matchingBoundRect, matchingBoundRect2;
isMatch = blm.findMatch(&contours, &src, &matchingContour, &matchingBoundRect);
isMatch2 = lm.findMatch(&contours, &src, &matchingContour2, &matchingBoundRect2);
if (isMatch && isMatch2) {
float dist = 4740.0 / matchingBoundRect.width;
cout << "Distance is " << dist << endl;
// Estimate dist from center
float leftL_RightMostX = matchingBoundRect.x + matchingBoundRect.width;
float rightL_LeftMostX = matchingBoundRect2.x;
float toteCenterX = (leftL_RightMostX + rightL_LeftMostX) / 2;
float frameCenter = src.cols/2;
float toteDeltaPix = frameCenter - toteCenterX;
Point p = Point(toteCenterX, 100);
Point p2 = Point(frameCenter, 100);
drawPoint(&src, &p, &BLUE);
drawPoint(&src, &p2, &RED);
float pixPer7Inches = matchingBoundRect.width; // pixels in 7 inches
float toteDeltaInches = toteDeltaPix / (pixPer7Inches/7);
cout << "toteDeltaInches = " << toteDeltaInches << endl;
}
/// Show in a window
imshow( "Contours", drawing );
imshow( "Src", src );
waitKey(0);
return 0;
}