Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewFrameEvent never fired when videoSource.Start() is called #43

Open
arepp23 opened this issue Jul 16, 2020 · 6 comments
Open

NewFrameEvent never fired when videoSource.Start() is called #43

arepp23 opened this issue Jul 16, 2020 · 6 comments

Comments

@arepp23
Copy link

arepp23 commented Jul 16, 2020

I am using AForge in a console application, following the sample for snapshot capture. When I call videoSource.Start(), the method for handling the new video frame event is never hit. Here's the code:

static void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            // get new frame
            Bitmap bitmap = eventArgs.Frame;
            // process the frame
        }

        static void CameraSetup()
        {
            var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            // create video source
            VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
            Console.WriteLine(videoDevices[0].Name);
            // set NewFrame event handler
            videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
            // start the video source
            videoSource.Start();
            System.Threading.Thread.Sleep(10000);
            // ...
            // signal to stop when you no longer need capturing
            videoSource.SignalToStop();
            // ...
        }
@JohnSWatson
Copy link

Try this:
Change
Bitmap bitmap = eventArgs.Frame;
To
Bitmap bitmap = new Bitmap(eventArgs.Frame)

@arepp23
Copy link
Author

arepp23 commented Jul 17, 2020

@JohnSWatson the issue isn't getting the bitmap, when I set a breakpoint on that line it's never getting hit. It's as if the event is never fired. I also added the error handler event and that one is not being hit either, so I don't know how to debug this.

@JohnSWatson
Copy link

Sorry, my application uses 6 cameras which are handled in series, so my code is convoluted. It would help if you supplied all details and relevant code.

However, if the handler is not being called, then it is not it my not be being subscribed to, you may be missing the “object sender, …” parameter.

Please refer to the Aforge docs at http://www.aforgenet.com/framework/docs/html/4cf2f0c9-4b5b-2666-290a-6b37a11e8e4f.htm and http://www.aforgenet.com/framework/features/directshow_video.html

If this does not help try writing a minimum fail program (the minimum code which fails) and post that code.

@MarcioGabe
Copy link

MarcioGabe commented Sep 18, 2020

I just had the same problem on a few machines with Windows 10 using Logitech's C270 Camera, and it turns out they all had Kaspersky Endpoint Security 11 antivirus installed and it was somehow blocking our application. Strangely enough the Windows camera app and the browsers (Firefox or Chrome) were working without any issues. Maybe something related to trusted applications being allowed access or something like that while our software was not.

The behavior as I was able to track was such that when calling videoSource.Start() just like in the example above, the LED in the camera would actually turn on as expected, no error was being produced (using the videoSource.VideoSourceError += VideoSource_VideoSourceError;), but the videoSource.NewFrame was never called at all... thus no bitmap to process or show in the picturebox... videoSource.IsRunning would return True, and after calling videoSource.SignalToStop(); the LED of the camera turned off as expected.

I even tried the AForge sample applications and one other application written using DirectX.Capture.dll and they showed the same behavior (Webcam LED turns ON, no image in the app).

I could not test playing around with the Kaspersky options because the network admins password protected it, but to prove the point I was able to uninstall it completely from one machine and magically the app just worked. So for sure Kaspersky was blocking it somehow (maybe it uses some directshow filter or who knows what to prevent untrusted apps from accessing the camera). The AForge sample application and the other one using DirectX.Capture.Capture also worked. So... since it took me a while to solve this one, I figured I should share it here or somewhere... so others may be pointed in the right direction if experiencing something similar.

@Niko-O
Copy link

Niko-O commented May 8, 2022

I have the same problem, but I don't have Kaspersky installed. It's a fresh install of Windows 7 with Defender's realtime protection disabled. Firefox can access the camera just fine.

@harisdha
Copy link

harisdha commented Jul 24, 2023

i have the same problem,
here is the detail from kapersky log report

Host Intrusion Prevention
Event: Application is not allowed to access the webcam
Component: Host Intrusion Prevention
Result description: Blocked
Type: Security settings access
Name: Rights
Threat level: High
Object type: Webcam
Reason: Rights

then i go to kapersky endpoint security,
tab "Security" -> "Advanced protection" -> "Host Intrusion Prevention" -> Settings -> "Manage Applications" -> set application as restriction trusted.

now my app can access webcam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants