Browse Source

Better error handling for Mac demo

pull/275/head
Canming Huang 6 years ago
parent
commit
6022e77124
  1. 2
      Emgu.CV.Example/Mac/Emgu.CV.Example.Mac.csproj
  2. 14
      Emgu.CV.Example/Mac/ViewController.cs

2
Emgu.CV.Example/Mac/Emgu.CV.Example.Mac.csproj

@ -151,9 +151,11 @@
<ItemGroup>
<Content Include="..\..\opencv\data\haarcascades\haarcascade_eye.xml">
<Link>haarcascade_eye.xml</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\opencv\data\haarcascades\haarcascade_frontalface_default.xml">
<Link>haarcascade_frontalface_default.xml</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\FaceDetection\lena.jpg">
<Link>lena.jpg</Link>

14
Emgu.CV.Example/Mac/ViewController.cs

@ -56,6 +56,8 @@ namespace Emgu.CV.Example.Mac
}
void RunDetectFace()
{
try
{
//Read the files as an 8-bit Bgr image
NSImage nsImage = NSImage.ImageNamed("lena.jpg");
@ -77,6 +79,14 @@ namespace Emgu.CV.Example.Mac
CvInvoke.Rectangle(image, eye, new Bgr(Color.Blue).MCvScalar, 2);
mainImageView.Image = image.ToNSImage();
} catch (Exception e)
{
InvokeOnMainThread(() =>
{
messageLabel.StringValue = e.Message;
messageLabel.InvalidateIntrinsicContentSize();
});
}
}
void RunFeatureMatching()
@ -119,7 +129,7 @@ namespace Emgu.CV.Example.Mac
private void ProcessFrame(object sender, EventArgs arg)
{
if (_capture != null && _capture.Ptr != IntPtr.Zero)
if (_capture != null && _capture.Ptr != IntPtr.Zero && _capture.IsOpened)
{
_capture.Retrieve(_frame, 0);
var nsImage = _frame.ToNSImage();
@ -137,11 +147,11 @@ namespace Emgu.CV.Example.Mac
_capture = new VideoCapture();
if (_capture == null || !_capture.IsOpened)
{
_capture = null;
InvokeOnMainThread(() =>
{
messageLabel.StringValue = "unable to create capture";
});
_capture = null;
return;
}
_capture.ImageGrabbed += ProcessFrame;

Loading…
Cancel
Save