Quantcast
Channel: Multimedia Imaging – LEADTOOLS Blog
Viewing all articles
Browse latest Browse all 10

Integrate LEADTOOLS Computer Vision Solutions: Multimedia and Motion Detection

0
0

Computer vision is a field of artificial intelligence that trains computers to interpret and understand the visual world. Using digital images from cameras and videos and deep learning models, machines can accurately identify and classify objects — and then react to what they “see”. LEADTOOLS is built upon nearly 30 years of programming and patented AI algorithms dealing with the understanding of images and videos. When it comes to putting computer vision into practice, we’ve got you covered!

In this post, I’ll go over how you can incorporate computer vision into your application using the LEADTOOLS Multimedia SDK. The LEAD Motion Detection filter is just one of the many LEADTOOLS computer vision and AI features offered with the SDK. The Motion Detection has a callback that will be fired every time that the current frame of a video does not match the previous frame. The filter will also draw rectangles around areas on the video where motion has been detected. This is perfect solution to use AI for surveillance or when working with UAV applications.

The LEAD Motion Detection filter provides a user interface that you can add to your app which is used for changing the filter’s attributes. It allows you to change the sensitivity, adjust the object size, and more.

Now let’s get to the code!


Download Project!

To see the full application, please download the proejct from the link provided above. The code shown below is the relevant information for initializing and using the LEADTOOLS CallBack Filter as well as the Motion Detection Filter

Create a new class in the project and name it MtnDtCallback. Add the following code.

public class MtnDtCallback : ILMVMtnDetUserCallback
{
    public System.Windows.Forms.ListBox LstBx;
    public MotionFrameClass mtnClass = new MotionFrameClass();
    public int CrtFrame = 0;
    public void MtnDtCallbackfnc()
    {

    }
    ~MtnDtCallback()
    {

    }
    public int CallbackProc(int lEvent, int pFrame, int lWidth, int lHeight, int lBitCount, int lSize, bool bTopDown)
    {
        if (lEvent == (int)LMVMtnDetLib.FrameTypeConstants.FRAME_TYPE_STARTMOTION)
        {
            mtnClass.Started = true;
            mtnClass.StartFrame = CrtFrame;
        }
        if (lEvent == (int)LMVMtnDetLib.FrameTypeConstants.FRAME_TYPE_STARTSTILL)
        {
            if (mtnClass.Started)
            {
                mtnClass.EndFrame = CrtFrame - 1;
                String x = mtnClass.StartFrame.ToString() + "-" + mtnClass.EndFrame.ToString();
                LstBx.Items.Add(x);
                mtnClass.Started = false;
                mtnClass.StartFrame = 0;
                mtnClass.EndFrame = 0;
            }
        }
        CrtFrame = CrtFrame + 1;
        return (int)MtnCalBkErrConstants.MTNCALBK_ERR_SUCCESS;
    }
    public class MotionFrameClass
    {
        public bool Started = false;
        public Int64 StartFrame = 0;
        public Int64 EndFrame = 0;
    }
}

Now you will want to create a new form and name that one ConvertForm. This is where you will find the code that starts the motione detection.

convertCtrl1.Preview = true;
convertCtrl1.Progress += new Leadtools.Multimedia.ProgressEventHandler(convertCtrl1_Progress);
convertCtrl1.SourceFile = SrcFile;
convertCtrl1.TargetFormat = TargetFormatType.NULL;
mtnCllbck = new MtnDtCallback();
mtnCllbck.LstBx = LstBox;
if ((convertCtrl1.AllowedStreams & StreamFormatType.Video) == StreamFormatType.Video)
{
    Processor mtnDet = convertCtrl1.VideoProcessors.MotionDetection;
    convertCtrl1.SelectedVideoProcessors.Add(mtnDet);
    motion = convertCtrl1.GetSubObject(ConvertObject.SelVideoProcessor) as LMVMtnDetLib.ILMVMt
    motion.CallbackObj = mtnCllbck;
    motion.MinStillTime = 1000;
    motion.Interval = 0;
    motion.AutoStart = true;
    motion.EnableRegion = false;
}
convertCtrl1.StartConvert();
motion.StartDetection();

The project will create a list of all the movement that were processed. Double clicking on one of the frame ranges from the list will then play that range of frames so you can see the movement.


Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images