资源简介

利用opencv开发的车道检测和车辆识别代码。包含源代码、目的代码、演示视频。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

using OpenCvSharp;

namespace LaneDetection
{
    class Program
    {
        [STAThread]
        static void Main()
        {
            CvCapture cap = CvCapture.FromFile(“road.avi“);
            CvWindow w = new CvWindow(“Lane Detection“);
            IplImage src gray dstCanny halfframe smallImg;
            CvMemStorage storage = new CvMemStorage();
            CvSeq lines;
            CvHaarClassifierCascade cascade = CvHaarClassifierCascade.FromFile(“haarcascade_cars3.xml“);

            const double Scale = 2.0;
            const double ScaleFactor = 1.05;
            const int MinNeighbors = 2;

            CvSeq cars;

            while (CvWindow.WaitKey(10) < 0)
            {
                src = cap.Queryframe();
                halfframe = new IplImage(new CvSize(src.Size.Width / 2 src.Size.Height / 2) BitDepth.U8 3);
                Cv.PyrDown(src halfframe CvFilter.Gaussian5x5);

                gray = new IplImage(src.Size BitDepth.U8 1);
                dstCanny = new IplImage(src.Size BitDepth.U8 1);


                smallImg = new IplImage(new CvSize(Cv.Round(src.Width / Scale) Cv.Round(src.Height / Scale)) BitDepth.U8 1);
                using (IplImage grey = new IplImage(src.Size BitDepth.U8 1))
                {
                    Cv.CvtColor(src grey ColorConversion.BgrToGray);
                    Cv.Resize(grey smallImg Interpolation.Linear);
                    Cv.EqualizeHist(smallImg smallImg);
                }

                storage.Clear();
                cars = Cv.HaarDetectobjects(smallImg cascade storage ScaleFactor MinNeighbors HaarDetectionType.DoCannyPruning new CvSize(30 30));

                for (int i = 0; i < cars.Total; i++)
                {
                    CvRect r = cars[i].Value.Rect;
                    CvPoint center = new CvPoint
                    {
                        X = Cv.Round((r.X + r.Width * 0.5) * Scale)
                        Y = Cv.Round((r.Y + r.Height * 0.5) * Scale)
                    };
                    int radius = Cv.Round((r.Width + r.Height) * 0.25 * Scale);
                    src.Circle(center radius CvColor.Blue 2 LineType.AntiAlias 0);
                }

                // Crop off top half of image since we‘re only interested in the lower portion of the video
                int halfWidth = src.Width / 2;
                int halfHeight = src.Height / 2;
                int startX = halfWidth - (halfWidth / 2);
                src.SetROI(new CvRect(0 halfHeight - 0 src.Width - 1 src.Height - 1));

                gray.SetROI(src.GetROI());
                dstCanny.SetROI(src.GetROI());

                src.CvtColor(gray ColorConversion.BgrToGray);
                Cv.Smooth(gray gray SmoothType.Gaussian 5 5);
                Cv.Canny(gra

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        144  2010-11-14 11:46  LaneDetection\LaneDetection\app.config

     文件     118803  2013-05-11 08:40  LaneDetection\LaneDetection\bin\Debug\haarcascade_cars3.xml

     文件       7680  2013-05-13 20:24  LaneDetection\LaneDetection\bin\Debug\LaneDetection.exe

     文件        144  2010-11-14 11:46  LaneDetection\LaneDetection\bin\Debug\LaneDetection.exe.config

     文件      13824  2013-05-13 20:24  LaneDetection\LaneDetection\bin\Debug\LaneDetection.pdb

     文件      11600  2013-05-13 20:24  LaneDetection\LaneDetection\bin\Debug\LaneDetection.vshost.exe

     文件        144  2010-11-14 11:46  LaneDetection\LaneDetection\bin\Debug\LaneDetection.vshost.exe.config

     文件     470016  2012-05-19 09:21  LaneDetection\LaneDetection\bin\Debug\OpenCvSharp.dll

     文件     348160  2012-05-19 09:21  LaneDetection\LaneDetection\bin\Debug\OpenCvSharpExtern.dll

     文件     751616  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_calib3d231.dll

     文件     531968  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_contrib231.dll

     文件    1739776  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_core231.dll

     文件     895488  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_features2d231.dll

     文件    7417192  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_ffmpeg.dll

     文件     391680  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_flann231.dll

     文件     909824  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_highgui231.dll

     文件    1672192  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_imgproc231.dll

     文件     540672  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_objdetect231.dll

     文件     295936  2011-10-29 22:28  LaneDetection\LaneDetection\bin\Debug\opencv_video231.dll

     文件   13640312  2013-05-11 08:40  LaneDetection\LaneDetection\bin\Debug\road.avi

     文件     142552  2011-10-20 18:52  LaneDetection\LaneDetection\bin\Debug\tbb.dll

     文件       3200  2013-05-13 20:22  LaneDetection\LaneDetection\LaneDetection.csproj

     文件        143  2010-11-14 11:44  LaneDetection\LaneDetection\LaneDetection.csproj.user

     文件       4018  2013-05-13 20:21  LaneDetection\LaneDetection\Program.cs

     文件       1488  2013-05-13 20:20  LaneDetection\LaneDetection\Properties\AssemblyInfo.cs

     文件        885  2013-05-13 20:17  LaneDetection\LaneDetection.sln

     目录          0  2013-05-13 20:25  LaneDetection\LaneDetection\obj\x86\Debug

     目录          0  2013-05-13 20:25  LaneDetection\LaneDetection\obj\x86\Release

     目录          0  2013-05-13 20:24  LaneDetection\LaneDetection\bin\Debug

     目录          0  2013-05-13 20:20  LaneDetection\LaneDetection\bin\Release

............此处省略9个文件信息

评论

共有 条评论