OpencvSharp检测海天线

#define VIDEO
using OpenCvSharp;
using System;
namespace CaptureSeaLine
{
   
    class Program
    {
        static string rtspUrl = "rtsp://xxxx";

        static void Main(string[] args)
        {
            
            VideoCapture Capture = new VideoCapture(rtspUrl);
            Cv2.NamedWindow("test", WindowFlags.Normal);
            Cv2.NamedWindow("org", WindowFlags.Normal);
#if VIDEO
            while (Capture.IsOpened())
            {

                Mat img = new Mat();
                try
                {
                    Capture.Read(img);
                }
                catch
                {
                    Console.WriteLine( "no signal");
                }
                
                
                Mat imgGray = new Mat();
                Cv2.CvtColor(img, imgGray, ColorConversionCodes.BGR2GRAY);//灰度化
                Cv2.MedianBlur(imgGray, imgGray, 9);//中值滤波
                Cv2.Threshold(imgGray, imgGray, 0, 255, ThresholdTypes.Otsu);//二值化
                //Cv2.Threshold(imgGray, imgGray, 100, 250, ThresholdTypes.Tozero);

                Cv2.Canny(imgGray, imgGray, 10, 50, 3);//边沿检测
                LineSegmentPoint[] linePoint = Cv2.HoughLinesP(imgGray, 1.0, Cv2.PI / 180, 150, 300, 100);//霍夫直线检测
                //划线
                for (int i = 0; i < linePoint.Length; i++)
                {
                    Point p1 = linePoint[i].P1;
                    Point p2 = linePoint[i].P2;
                    Cv2.Line(img, p1, p2, Scalar.Green, 4);
                }
                //Cv2.ImShow("test", imgGray);
                Cv2.ImShow("org", img);
                Cv2.WaitKey(1);
            }
#else
            Mat img = Cv2.ImRead(@"D:\C#\Code\CaptureSeaLine\bin\Debug\SeaLine.png", ImreadModes.Color);
            Mat imgGray = new Mat();
            Cv2.CvtColor(img, imgGray, ColorConversionCodes.BGR2GRAY);
            Cv2.MedianBlur(imgGray, imgGray, 9);
            Cv2.Threshold(imgGray, imgGray, 0, 255, ThresholdTypes.Otsu);
            //Cv2.Threshold(imgGray, imgGray, 100, 250, ThresholdTypes.Tozero);

            Cv2.Canny(imgGray, imgGray, 10, 50, 3);
            LineSegmentPoint[] linePoint = Cv2.HoughLinesP(imgGray, 1.0, Cv2.PI / 180, 200, 300, 100);
            for (int i = 0; i < linePoint.Length; i++)
            {
                Point p1 = linePoint[i].P1;
                Point p2 = linePoint[i].P2;
                Cv2.Line(img, p1, p2, Scalar.Green, 4);
            }
            Cv2.ImShow("test", imgGray);
            Cv2.ImShow("org", img);
            Cv2.WaitKey(0);
#endif
        }
    }   
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值