What did I miss?
VS could not be found Capture and HaarCascade.
I added all opencv .dll and "Copy always".
And added References of Emgu.
My Emgu is emgucv-windesktop 3.2.0.2682-сuda. Visual Studio 2017
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;
using System.Windows;
namespace Emgu.FaceDetection
{
public partial class Form1 : Form
{
private Capture cap;
private HaarCascade haar;
public Form1()
{
InitializeComponent();
}
}
}
You can't use HaarCascade when using EmguCV3.X, it has been deprecated and replaced with CascadeClassifier
See here for an explination, the summary being it has changed to something akin to this:
CascadeClassifier _cascadeClassifier = new CascadeClassifier(#"C:\OPENCV_3.0.0\opencv\build\etc\haarcascades\" + "haarcascade_frontalface_alt2.xml");
A more complete example, and tutorial, using 3.X can be found here, a snippet from that blog:
private CascadeClassifier _cascadeClassifier;
_cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_alt_tree.xml");
using (var imageFrame = _capture.QueryFrame().ToImage<Bgr, Byte>())
{
if (imageFrame != null)
{
var grayframe = imageFrame.Convert<Gray, byte>();
var faces = _cascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty); //the actual face detection happens here
foreach (var face in faces)
{
imageFrame.Draw(face, new Bgr(Color.BurlyWood), 3); //the detected face(s) is highlighted here using a box that is drawn around it/them
}
}
imgCamUser.Image = imageFrame;
}
Related
I get "Not Found" errors in Xamarin Forms with things like NSFileManager and NSUrl. These are my imports of my class where I'm getting these errors:
using System;
using System.IO;
using System.Reflection;
using DrinkUp.Controls;
using DrinkUp.iOS.Renderers;
using MediaPlayer;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
And the class which I'm using is located in DrinkUp.iOS.
Whenever and wherever I type something with the NS prefix it says that it could not find the object. Can someone please tell me what I'm doing wrong here?
Here's my full class
using System;
using System.IO;
using System.Reflection;
using DrinkUp.Controls;
using DrinkUp.iOS.Renderers;
using MediaPlayer;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Video), typeof(VideoRenderer))]
namespace DrinkUp.iOS.Renderers
{
public class VideoRenderer : ViewRenderer<Video, UIView>
{
MPMoviePlayerController videoPlayer;
object notification = null;
void InitVideoPlayer()
{
var path = Path.Combine(NSBundle.MainBundle.BundlePath, Element.Source);
if (!NSFileManager.DefaultManager.FileExists(path)) {
Console.WriteLine("Video not exist");
videoPlayer = new MPMoviePlayerController();
videoPlayer.ControlStyle = MPMovieControlStyle.None;
videoPlayer.ScalingMode = MPMovieScalingMode.AspectFill;
videoPlayer.RepeatMode = MPMovieRepeatMode.One;
videoPlayer.View.BackgroundColor = UIColor.Clear;
SetNativeControl(videoPlayer.View);
return;
}
// Load the video from the app bundle.
NSUrl videoURL = new NUrl(path, false);
// Create and configure the movie player.
videoPlayer = new MPMoviePlayerController(videoURL);
videoPlayer.ControlStyle = MPMovieControlStyle.None;
videoPlayer.ScalingMode = MPMovieScalingMode.AspectFill;
videoPlayer.RepeatMode = Element.Loop ? MPMovieRepeatMode.One : MPMovieRepeatMode.None;
videoPlayer.View.BackgroundColor = UIColor.Clear;
foreach (UIView subView in videoPlayer.View.Subviews) {
subView.BackgroundColor = UIColor.Clear;
}
videoPlayer.PrepareToPlay();
SetNativeControl(videoPlayer.View);
}
}
}
The first comment worked, I had to get the NS types from Foundation.
Like Foundation.NSUrl etc. This fixed my problem.
using System.Text;
using System.Net.Http;
using Windows.ApplicationModel.Background;
using GrovePi.Sensors;
using GrovePi.Common;
using GrovePi.I2CDevices;
using System.IO;
using System.Data;
using Windows.Devices;
using GrovePi;
using System.Threading.Tasks;
using System.Diagnostics;
namespace CompassXYZ
{
public sealed class StartupTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
Pin Compass = Pin.DigitalPin3;
string CompassX = Compass.ToString();
string CompassY = Compass.ToString();
string CompassZ = Compass.ToString();
while (true)
{
System.Diagnostics.Debug.WriteLine($"X = {CompassX.GetHashCode()}, Y = {CompassY.GetHashCode()}, Z = {CompassZ.GetHashCode()}");
}
}
}
}
Hi Guys!
I'm a student trying to display 3 values from my Compass sensor on my GrovePi connected to my raspberry pi 3 running on Visual Studio 2015 Background Application, I need some pointers on how to display it correctly, so I really hope you guys could help me. Thanks!
I have got a problem when using EmguCV. Everytime I try to create SIFT or SURF detector I get exception "The type initializer for 'Emgu.CV.CvInvoke' threw an exception".
I've already: installed MSVCRT, copied OpenCV and Emgu dlls to the execution directory, added to solution OpenCV and Emgu dlls, added to solution Emgu.CV, Emgu.CV.GPU, Emgu.CV.ML, Emgu.CV.UI, Emgu.Util references.
Unfortunately I still got exception. I've tried to build SURFFeature example and it worked perfectly. It actually means that I make some mistake, but I can't find it... Please help...
Here's the code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Features2D;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Util;
using Emgu.CV.GPU;
namespace blablabla
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
Bitmap waveform_to_file = new Bitmap(2, 2);
//Emgu.CV.Features2D.SIFTDetector detector = new Emgu.CV.Features2D.SIFTDetector();//(0, 3, 0.04, 10, 1.6);//(400, true, 3, 4);//
SURFDetector surfCPU = new SURFDetector(500, false);//I got exception on these lines
Emgu.CV.Util.VectorOfKeyPoint keypoints = new Emgu.CV.Util.VectorOfKeyPoint();
Emgu.CV.Image<Emgu.CV.Structure.Gray, Byte> waveform_to_file_gray = new Emgu.CV.Image<Emgu.CV.Structure.Gray, byte>(waveform_to_file);
Emgu.CV.Features2D.ImageFeature<float>[] modKeyPointsArray = surfCPU/*detector*/.DetectFeatures(waveform_to_file_gray, null);
List<Emgu.CV.Features2D.ImageFeature<float>> modKeyPointsList = new List<Emgu.CV.Features2D.ImageFeature<float>>();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message + ex.StackTrace);
}
}
}
}
Solution explorer:
http://ifotos.pl/zobacz/4JPG_wwaerwh.jpg
bin/debug:
http://ifotos.pl/zobacz/3JPG_wwaereh.jpg
I'm new to the threading world and trying to make my application works with threads. Here is what I got:
public static void ThreadProc()
{
Thread.Sleep(500);
MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("SuperMMFofDoom", MemoryMappedFileRights.ReadWrite);
MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(0, sizeof(double)*3 + sizeof(int) *2);
Image imgS = new Image();
ImageTrigger myMessage;
Mutex imgMutex = new Mutex(false, "imgMutex");
while (threadRunning)
{
imgMutex.WaitOne();
accessor.Read(0, out myMessage);
// [...]
Dispatcher.Invoke(DispatcherPriority.Normal,
new Action(delegate()
{
// [...]
}),
new object[] { imgS, myMessage.performance }
);
imgMutex.ReleaseMutex();
}
}
This thing does compile when I comment all the Dispatcher.Invoke(). If I don't, I get an error about System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate, object) and it does not compile.
Any ideas?
I'm using VS2010 on Windows 7 Pro x64. This is a C# WPF project which also make use of some C++ DLLs also compiled in the same project. Finally, here is the header of the file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
using System.IO.MemoryMappedFiles;
using Common;
You should not be creating a new Action just casting your delegate as one:
Async:
Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)delegate()
{
});
Sync:
Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
});
Or if your not on a control or window:
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate()
{
});
I made a launcher for my game server. (World of Warcraft)
I want to get the installpath of the game, browsed by the user.
I'm using this code to browse, and get the installpath, then set some other strings from the installpath string, then just strore in my registry key.
using System;
using System.Drawing;
using System.Reflection;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Net.NetworkInformation;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using System.Net;
using System.Linq;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string InstallPath, WoWExe, PatchPath;
private void Form1_Load(object sender, EventArgs e)
{
RegistryKey LocalMachineKey_Existence;
MessageBox.Show("Browse your install location.", "Select Wow.exe");
OpenFileDialog BrowseInstallPath = new OpenFileDialog();
BrowseInstallPath.Filter = "wow.exe|*.exe";
if (BrowseInstallPath.ShowDialog() == DialogResult.OK)
{
InstallPath = System.IO.Path.GetDirectoryName(BrowseInstallPath.FileName);
WoWExe = InstallPath + "\\wow.exe";
PatchPath = InstallPath + "\\Data\\";
LocalMachineKey_Existence = Registry.LocalMachine.CreateSubKey(#"SOFTWARE\ExistenceWoW");
LocalMachineKey_Existence.SetValue("InstallPathLocation", InstallPath);
LocalMachineKey_Existence.SetValue("PatchPathLocation", PatchPath);
LocalMachineKey_Existence.SetValue("WoWExeLocation", WoWExe);
}
}
}
}
The problem is:
On some computer, it doesnt stores like it should be. For example, your wow.exe is in C:\ASD\wow.exe, your select it with the browse windows, then the program should store it in the Existence registry key as C:\ASD\Data\ but it stores like this:
C:\ASDData , so it forgots a backslash :S
Look at this picture:
http://img21.imageshack.us/img21/2829/regedita.jpg
My program works cool on my PC, and on my friends pc, but on some pc this "bug" comes out :S
I have windows 7, with .NEt 3.5
Please help me.
Can you debug and see what InstallPath contains?
Try it with Path.Combine instead of string concatenation, e.g.:
WowExe = Path.Combine(InstallPath, "wow.exe");
PatchPath = Path.Combine(InstallPath, #"\Data\");