Lane detection
一个使用C ++和OpenCV的简单车道检测器,用于识别车道并对其进行跟踪。检测车道并跟踪该点的运动,以确定车辆是否在转弯或正在改变坡度。项目源码
lane detection的下载
#安装opencv4.0及以上
#安装cmake3.0以上版本
git clone https://github.com/Nakalski/LaneDetection.git
有源码测试
测试代码
int main(int argc, char **argv)
{
const int lowThreshold = 20;
const int ratio = 3;
cv::VideoCapture cap;
std::string path = std::string(argv[1]);
//std::string path = "Videos/2.avi";
cap.open(path);
cv::Point2f obj_pts[4], img_pts[4];
img_pts[0].x = 150;
img_pts[0].y = 280; //B
img_pts[1].x = 50;
img_pts[1].y = 340; //G
img_pts[2].x = 530;
img_pts[2].y = 280; //R
img_pts[3].x = 630;
img_pts[3].y = 340; //Y
obj_pts[0].x = 0;
obj_pts[0].y = 0;
obj_pts[1].x = 0;
obj_pts[1].y = Y_warped;
obj_pts[2].x = X_warped;
obj_pts[2].y = 0;
obj_pts[3].x = X_warped;
obj_pts[3].y = Y_warped;
int n;
cv::Mat matrix, warped, gray, th, sum, inverted_matrix, frame, reduced_res, canny_test, mask, masked_drawed_lines, teste;
matrix = cv::getPerspectiveTransform(img_pts, obj_pts);
Mat invertedPerspectiveMatrix;
invert(matrix, invertedPerspectiveMatrix);
for (;;)
{
cap >> frame;
if (frame.empty())
break;
std::vector<cv::Vec4i> lines;
cv::pyrDown(frame, reduced_res);
/*cv::circle(reduced_res, img_pts[0], 1, cv::Scalar(255, 0, 0), 3);
cv::circle(reduced_res, img_pts[1], 1, cv::Scalar(0, 255, 0), 3);
cv::circle(reduced_res, img_pts[2], 1, cv::Scalar(0, 0, 255), 3);
cv::circle(reduced_res, img_pts[3], 1, cv::Scalar(0, 255, 255), 3); */
cv::warpPerspective(reduced_res, warped, matrix, cv::Size(X_warped, Y_warped));
cv::cvtColor(warped, gray, cv::COLOR_RGB2GRAY);
cv::Canny(warped, canny_test, lowThreshold, lowThreshold * ratio, 3, true);
cv::dilate(canny_test, mask, Mat(), Point(-1, -1), 1, 1, 1);
cv::morphologyEx(mask, mask, cv::MORPH_CLOSE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(10, 10)));
cv::morphologyEx(mask, mask, cv::MORPH_CLOSE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(10, 10)));
cv::threshold(gray, th, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
cv::bitwise_and(th, mask, teste); /// MAS
vector<Point2f> pts = slidingWindow(teste, Rect(0,210,60,30));
vector<Point> allPts;
vector<Point2f> outPts;
cv::perspectiveTransform(pts, outPts, invertedPerspectiveMatrix);
for (int i = 0; i < outPts.size() - 1; ++i)
{
cv::line(reduced_res, outPts[i], outPts[i + 1], Scalar(255, 0, 0), 3);
allPts.push_back(Point(outPts[i].x, outPts[i].y));
}
allPts.push_back(Point(outPts[outPts.size() - 1].x, outPts[outPts.size() - 1].y));
Mat out;
cv::cvtColor(teste, out, COLOR_GRAY2BGR);
for (int i = 0; i < pts.size() - 1; ++i)
line(out, pts[i], pts[i + 1], Scalar(255, 0, 0));
pts = slidingWindow(teste, Rect(260, 210, 60, 30));
cv::perspectiveTransform(pts, outPts, invertedPerspectiveMatrix);
for (int i = 0; i < outPts.size() - 1; ++i)
{
line(reduced_res, outPts[i], outPts[i + 1], Scalar(0, 0, 255), 3);
allPts.push_back(Point(outPts[outPts.size() - i - 1].x, outPts[outPts.size() - i - 1].y));
}
allPts.push_back(Point(outPts[0].x - (outPts.size() - 1) , outPts[0].y));
for (int i = 0; i < pts.size() - 1; ++i)
line(out, pts[i], pts[i + 1], Scalar(0, 0, 255));
vector<vector<Point>> arr;
arr.push_back(allPts);
Mat overlay = Mat::zeros(reduced_res.size(), reduced_res.type());
cv::fillPoly(overlay, arr, Scalar(0, 255, 100));
cv::addWeighted(reduced_res, 1, overlay, 0.5, 0, reduced_res); //Overlay it
cv::imshow("Preprocess", out);
cv::imshow("src", reduced_res);
cv::imshow("WarpedPerspective", gray);
if (cv::waitKey(33) >= 0)
break;
}
return 0;
}
配置
对于完整的项目,需要将编译器指定为 afl-clang,然后再进行编译。
export CC=afl-clang
export CXX=afl-clang++
mkdir build
cd build
cmake ../
make -j4
fuzz
正式执行 fuzz 测试的命令如下:
mkdir in
# 在in文件下下创建image语料库,使用png.dict字典
# https://github.com/AFLplusplus/AFLplusplus/tree/stable/dictionaries
afl-fuzz -x dict/png.dict -m none -i in -o out_res ./Main @@