OPENCV车道检测与车辆识别


利用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  LaneDetectionLaneDetectionapp.config

     文件     118803  2013-05-11 08:40  LaneDetectionLaneDetectioninDebughaarcascade_cars3.xml

     文件       7680  2013-05-13 20:24  LaneDetectionLaneDetectioninDebugLaneDetection.exe

     文件        144  2010-11-14 11:46  LaneDetectionLaneDetectioninDebugLaneDetection.exe.config

     文件      13824  2013-05-13 20:24  LaneDetectionLaneDetectioninDebugLaneDetection.pdb

     文件      11600  2013-05-13 20:24  LaneDetectionLaneDetectioninDebugLaneDetection.vshost.exe

     文件        144  2010-11-14 11:46  LaneDetectionLaneDetectioninDebugLaneDetection.vshost.exe.config

     文件     470016  2012-05-19 09:21  LaneDetectionLaneDetectioninDebugOpenCvSharp.dll

     文件     348160  2012-05-19 09:21  LaneDetectionLaneDetectioninDebugOpenCvSharpExtern.dll

     文件     751616  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_calib3d231.dll

     文件     531968  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_contrib231.dll

     文件    1739776  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_core231.dll

     文件     895488  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_features2d231.dll

     文件    7417192  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_ffmpeg.dll

     文件     391680  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_flann231.dll

     文件     909824  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_highgui231.dll

     文件    1672192  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_imgproc231.dll

     文件     540672  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_objdetect231.dll

     文件     295936  2011-10-29 22:28  LaneDetectionLaneDetectioninDebugopencv_video231.dll

     文件   13640312  2013-05-11 08:40  LaneDetectionLaneDetectioninDebug
oad.avi

     文件     142552  2011-10-20 18:52  LaneDetectionLaneDetectioninDebug bb.dll

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

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

     文件       4018  2013-05-13 20:21  LaneDetectionLaneDetectionProgram.cs

     文件       1488  2013-05-13 20:20  LaneDetectionLaneDetectionPropertiesAssemblyInfo.cs

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

     目录          0  2013-05-13 20:25  LaneDetectionLaneDetectionobjx86Debug

     目录          0  2013-05-13 20:25  LaneDetectionLaneDetectionobjx86Release

     目录          0  2013-05-13 20:24  LaneDetectionLaneDetectioninDebug

     目录          0  2013-05-13 20:20  LaneDetectionLaneDetectioninRelease

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)