第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

為運(yùn)動(dòng)檢測(cè)設(shè)置指定區(qū)域

為運(yùn)動(dòng)檢測(cè)設(shè)置指定區(qū)域

C#
森林海 2022-07-10 16:11:36
我需要指定將發(fā)生運(yùn)動(dòng)檢測(cè)的區(qū)域。我要做的是計(jì)算通過某個(gè)區(qū)域的車輛數(shù)量。下面是我的代碼:private static void ProcessFrame(Mat backgroundFrame, int threshold, int erodeIterations, int dilateIterations){    // Find difference between background (first) frame and current frame    CvInvoke.AbsDiff(backgroundFrame, rawFrame, diffFrame);    // Apply binary threshold to grayscale image (white pixel will mark difference)    CvInvoke.CvtColor(diffFrame, grayscaleDiffFrame, ColorConversion.Bgr2Gray);    CvInvoke.Threshold(grayscaleDiffFrame, binaryDiffFrame, threshold, 255, ThresholdType.Binary);    // Remove noise with opening operation (erosion followed by dilation)    CvInvoke.Erode(binaryDiffFrame, denoisedDiffFrame, null, new Point(-1, -1), erodeIterations, BorderType.Default, new MCvScalar(1));    CvInvoke.Dilate(denoisedDiffFrame, denoisedDiffFrame, null, new Point(-1, -1), dilateIterations, BorderType.Default, new MCvScalar(1));    rawFrame.CopyTo(finalFrame);    //Rectangle rec = new Rectangle(100, 100, 100, 100);    //finalFrame = crop_color_frame(rawFrame, rec);    var img = crop_color_frame(denoisedDiffFrame, rec);    DetectObject(denoisedDiffFrame, finalFrame);}static int vnum = 0;private static void DetectObject(Mat detectionFrame, Mat displayFrame){    using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())    {        // Build list of contours        CvInvoke.FindContours(detectionFrame, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);        // Selecting largest contour        if (contours.Size > 0)        {            double maxArea = 0;            int chosen = 0;            for (int i = 0; i < contours.Size; i++)            {目前,此代碼可用于檢測(cè)車輛,但我只是使用if(center.Y >= 100 && maxArea > 20000) 條件開始計(jì)算車輛這種方法的問題是,框架中的所有運(yùn)動(dòng)都受到監(jiān)控。這就是為什么我只需要設(shè)置一個(gè)特定的區(qū)域。你能告訴我怎么做嗎?
查看完整描述

1 回答

?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

您可以為輸入圖像設(shè)置 ROI


public static Mat crop_roi(Mat input_img)

{

    Image<Gray, byte> img = input_img.ToImage<Gray, byte>();

    double w = input_img.Width;

    double h = input_img.Height;

    Rectangle r = new Rectangle((int)(w * 0.2), (int)(h * 0.4), (int)(w * 0.6), (int)(h * 0.6));

    Image<Gray, byte> output = img.Copy(r);


    return output.Mat;

}


//USE

private static void DetectObject(Mat detectionFrame, Mat displayFrame)

{

    using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())

    { 

        //set roi to the frame

        Mat roi = new Mat()

        roi = set_roi(detectionFrame);


        // Build list of contours

        CvInvoke.FindContours(roi , contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);


        // Selecting largest contour

        ...


        MarkDetectedObject(roi , contours[chosen], maxArea, contours.Size, maxArea);


 }

下面是我在一張圖片中繪制 ROI 的圖片,您可以通過更改此行中的參數(shù)來調(diào)整 ROIRectangle r = new Rectangle((int)(w * 0.2), (int)(h * 0.4), (int)(w * 0.6), (int)(h * 0.6));

http://img1.sycdn.imooc.com//62ca89ea000148ce07760696.jpg

查看完整回答
反對(duì) 回復(fù) 2022-07-10
  • 1 回答
  • 0 關(guān)注
  • 109 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)