-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetector.cpp
More file actions
77 lines (61 loc) · 1.98 KB
/
Copy pathdetector.cpp
File metadata and controls
77 lines (61 loc) · 1.98 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
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <opencv2/opencv.hpp>
#include <cv_bridge/cv_bridge.h>
#include "opencv2/imgproc/imgproc.hpp"
// Global variables used in canny edge detection
int lowThreshold = 10;
int kernelSize = 3;
int ratio = 3;
// Robots mask
///////////////////// Size and values pof the mask /////////////////////
int maskSize = 3;
cv::Mat robotMask = cv::Mat::ones(maskSize, maskSize, CV_8UC1);
/*
Apply the canny edge detector in the gray scale imnage
*/
void applyCanny(const cv::Mat& inImage, cv::Mat* outImage)
{
// Reduse the noise in the input image
cv::blur(inImage, *outImage, cv::Size(3, 3));
//cv::imshow("Blured image", *outImage);
// Apply Canny detector
cv::Canny(*outImage, *outImage,
lowThreshold, lowThreshold * ratio, kernelSize);
//cv::imshow("Canny image", *outImage);
}
int main(int argc, char** argv)
{
// The input image
cv::Mat inputImage;
inputImage = cv::imread("obstacle.png");
if (! inputImage.data)
{
std::cout << ("No image data");
return -1;
}
// Show the input image
cv::imshow("InputImage", inputImage);
// Image to gray scale
cv::Mat grayImage;
cvtColor(inputImage, grayImage, CV_BGR2GRAY);
// Find the gradient differences aka Dangerous areas
cv::Mat edgesImage;
applyCanny(grayImage, &edgesImage);
// All edges will be represented by value of 255
cv::threshold(edgesImage, edgesImage, 0, 255, cv::THRESH_BINARY);
cv::imshow("Edges after thresholding", edgesImage);
///////// Fill the edges map with the unkown values from inputImage //////////
// Pass the robot through all the map and make the new map
cv::Mat newMap;
cv::filter2D(edgesImage, newMap, -1, robotMask,
cv::Point(-1, -1), 0, cv::BORDER_DEFAULT);
cv::imshow("The new map", newMap);
//////// If values in map < 0 set as -1
//////// Else if > 0 threshold to 100
//////// If 0 as it is
cv::waitKey();
return 0;
}