我想通过使用地面机器人将覆盖的区域的无人机拍摄的照片来对地面机器人进行障碍检测。由于我在图像处理方面的背景有限,因此我不确定如何执行此操作。我尝试使用以下方法,但结果不是很准确。它也检测到非常小的边缘,并且不适用于航空影像。
#pragma once
#include <string>
#include <iostream>
#include <vector>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
//----------------------------------------------------------
// MAIN
//----------------------------------------------------------
int main(int argc, char* argv[])
{
// src image
Mat src;
//grayscale image
Mat gray;
// edges image
Mat edges;
//dst image
Mat dst;
//eroded image
Mat erosion;
//smoothed result
Mat result;
//----------------------------------------------------------
// Image loading
//----------------------------------------------------------
namedWindow("result");
namedWindow("src");
namedWindow("edges");
src = imread("C:/Users/HP/Desktop/SDP/obstacle detection/obstacle detection/obstacle detection/shapes.jpg");
//----------------------------------------------------------
//Specifying size and type of image
//----------------------------------------------------------
edges = Mat::zeros(src.size(), CV_8UC1);
dst = Mat::zeros(src.size(), CV_8UC1);
gray= Mat::zeros(src.size(), CV_8UC1);
erosion = Mat::zeros(src.size(), CV_8UC1);
result = Mat::zeros(src.size(), CV_8UC1);
//----------------------------------------------------------
//Converting from RGB to grayscale
//----------------------------------------------------------
cvtColor(src, gray, COLOR_BGR2GRAY);
//----------------------------------------------------------
//Edge Detetcion using OpenCV Canny Edge Detector function
//----------------------------------------------------------
Canny(gray, edges, 80, 255);
//----------------------------------------------------------
//Filling in the non-obstacle areas with white
//----------------------------------------------------------
for (int i = 0; i<edges.cols; ++i)
{
int j = edges.rows - 1;
for (j = edges.rows - 1; j>0; --j)
{
if (edges.at<uchar>(j, i)>0)
{
break;
}
}
dst(Range(j, dst.rows - 1), Range(i, i + 1)) = 255;
}
//----------------------------------------------------------
// Appying erosion function to remove noise
//----------------------------------------------------------
Mat element = getStructuringElement(MORPH_RECT, Size(10, 10));
erode(dst,erosion,element);
//----------------------------------------------------------
//Smoothing the edges to get result
//----------------------------------------------------------
GaussianBlur(erosion, result, Size(5,5), 4);
//----------------------------------------------------------
// Displaying the intermediate and final resulting images
//----------------------------------------------------------
namedWindow("src", WINDOW_NORMAL);
imshow("src", src);
namedWindow("edges", WINDOW_NORMAL);
imshow("edges", edges);
namedWindow("dst", WINDOW_NORMAL);
imshow("dst", dst);
namedWindow("erosion", WINDOW_NORMAL);
imshow("erosion", erosion);
namedWindow("result", WINDOW_NORMAL);
imshow("result", result);
//----------------------------------------------------------
// Wait key press
//----------------------------------------------------------
waitKey(0);
destroyAllWindows();
return 0;
}
代码获取图像,并将其转换为灰度。然后,使用Canny边缘检测来检测图像中所有对象的边缘。从底部开始直到检测到边缘为止,该边缘检测图像被白色填充为白色。该过程一直进行到覆盖整个图像为止。结果是二进制图像,无障碍区域为白色,障碍物为黑色。然后使用opencv函数侵蚀来消除不必要的噪音。
如果能提出改进建议或使用其他任何技术,我将不胜感激。
答案 0 :(得分:0)
我建议将图像阈值设置为与地面匹配的颜色范围。如果地面的颜色变化不大(在src图像中就是这种情况),则此方法效果很好。 You might want to check out this OpenCV example (Python).