I am getting an unhandled exception when trying to create a D3d device.
This is literally the whole code in C#. I am just testing and trying to learn directx.
I am getting the Unhandled exception on this line
: device = new Device(0, DeviceType.Hardware, this,CreateFlags.SoftwareVertexProcessing, presentParams);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Device device = null; // Create rendering device
PresentParameters presentParams = new PresentParameters();
device = new Device(0, DeviceType.Hardware, this,CreateFlags.SoftwareVertexProcessing, presentParams);
RenderToSurface render = new RenderToSurface(device, 300, 300, Format.D32, true, DepthFormat.D32);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Kind of blowing my mind because it looks like all the params are right..
needed presentParams.Windowed = true in order for this to work.
Related
I am testing out EMGU for a school assignment, and I am following this tutorial to get a basic understanding with the way EMGU works, but I have a problem.
Here is my code:
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.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
namespace FacialRecognition
{
public partial class Form1 :Form
{
private Capture _capture;
bool CapturingProcess = false;
Image<Bgr, Byte> imgOrg;
Image<Gray, Byte> imgProc;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try {
_capture = new Capture(CaptureType.DShow);
} catch(NullReferenceException ex) {
MessageBox.Show(ex.Message);
return;
}
}
void processFunction(object sender, EventArgs e)
{
imgOrg = _capture.QueryFrame();
if(imgOrg == null) return;
imgProc = imgOrg.InRange(new Bgr(50, 50, 50), new Bgr(255, 255, 255));
imgProc = imgProc.SmoothGaussian(9);
original.Image = imgOrg;
processed.Image = imgProc;
}
}
}
However, I get the error:
The type or namespace name 'Capture' could not be found (are you missing a using directive or an assembly reference?)
and it suggests using System.Text.RegularExpressions;, which is quite strange.
I'm guessing I am missing something, but I referenced all of the DLL's
in the tutorial. Here are some screenshots:
Solution Explorer (They are set to Copy always)
References (Emgu.CV.World.NetStandard1_4.dll and Emgu.CV.World.dll were colliding)
Capture has been renamed to VideoCapture in new versions of EMGU , so try
private VideoCapture _capture;
You might consider using Emgu.CV.VideoCapture in EMGU.CV NuGet package (http://www.emgu.com/wiki/index.php/Main_Page) instead of Capture. So, your declaration becomes:
private VideoCapture _capture;
I have this code that uses NAudio to look for all microphones connected on laptop, andwhen I choose one it shows a meter of the sound in a progressbar.
when I gather all device, I collect them in a dropdwon list, my issue is that when I choose the one microphone from the list it will not be activated and display the sound on a meter unless I start WINDOWS SOUND RECORDER which seems to activate the mic.
how to enable or activate the microphone from the code without starting WINDOWS SOUND RECORDER?
here is the code:
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 NAudio;
using NAudio.CoreAudioApi;
using System.Threading;
using NAudio.Wave;
using NAudio.Mixer;
namespace NaudioVisualizer
{
public partial class Form1 : Form
{
public int a = 1;
public Form1()
{
InitializeComponent();
MMDeviceEnumerator de = new MMDeviceEnumerator();
var device = de.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active);
comboBox1.Items.AddRange(device.ToArray());
}
private void timer1_Tick(object sender, EventArgs e)
{
if (comboBox1.SelectedItem != null)
{
var device = (MMDevice)comboBox1.SelectedItem;
progressBar1.Value = (int)Math.Round(device.AudioMeterInformation.MasterPeakValue * 100);
}
}
}
}
I had the same problem try to use the following code :
var waveIn = new WaveIn();
waveIn.StartRecording();
I'm new here hoping for some help with geckoFX in C#
So I just downloaded the geckoFX and did the following.
Downloaded: geckofx.dll
downloaded: XULRunner
I added the geckofx browser successfully and works fine but when I try to run this code to add JavaScript to the page I get an error.
The error I'm getting is: skybound.geckoFX.AutoJSContext does not contain a definition for evaluate script and jscontext.
Also I don't know if this helps but AutoJSContext and EvaluateScript are not hightlighting.
Here is my code
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Skybound.Gecko;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Skybound.Gecko.Xpcom.Initialize(#"C:\Program Files\xulrunner");
}
private void geckoWebBrowser1_DocumentCompleted(object sender, EventArgs e)
{
string outString = "";
using (AutoJSContext java = new AutoJSContext(geckoWebBrowser1.Window.JSContext))
{
java.EvaluateScript(#"window.alert('alert')", out outString);
}
}
}
You should call EvaluateScript like so:
java.EvaluateScript(#"window.alert('alert')", (nsISupports)geckoWebBrowser1.Window.DomWindow, out result);
I want to be able to get input from a microphone device via NAudio.WaveIn, and then output that exact input to an output device via NAudio.WaveOut.
How would I do this?
Here is the code that worked for me:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NAudio.Wave;
using NAudio.CoreAudioApi;
namespace WindowsFormsApplication1
{
public partial class Form4 : Form
{
private BufferedWaveProvider bwp;
WaveIn wi;
WaveOut wo;
public Form4()
{
InitializeComponent();
wo = new WaveOut();
wi = new WaveIn();
wi.DataAvailable += new EventHandler<WaveInEventArgs>(wi_DataAvailable);
bwp = new BufferedWaveProvider(wi.WaveFormat);
bwp.DiscardOnBufferOverflow = true;
wo.Init(bwp);
wi.StartRecording();
wo.Play();
}
void wi_DataAvailable(object sender, WaveInEventArgs e)
{
bwp.AddSamples(e.Buffer, 0, e.BytesRecorded);
}
}
}
The best way would be to use a BufferedWaveProvider as the input to WaveOut. Then in the DataAvailable callback of WaveIn, supply the data recorded to the BufferedWaveProvider
void DataAvailable(object sender, WaveInEventArgs args)
{
bufferedWaveProvider.AddSamples(args.Buffer, 0, args.BytesRecorded);
}
You need to be aware that the default buffer sizes will result in a noticeable delay, so if you were hoping for low latency you might need to experiment a bit with buffer sizes to see how low you can get it.
I'm a newbie in emgu cv and for a major project I'm trying to capture an image from a webcam and show it in an image box, but it's showing a black image.
What is wrong with the following code?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.Util;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
private Capture capture;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
if (capture == null)
capture = new Capture();
Image<Bgr,Byte> img=capture.QueryFrame();
imageBox1.Image = img;
}
}
}
I think there is a minor mistake.
Use this instead:
Declare as global variable:
Capture capture = default(Capture);
Put this in load:
capture = new Capture(0);
Control.CheckForIllegalCrossThreadCalls = false;
System.Threading.Thread t = new System.Threading.Thread(grab);
t.Start();
Create a sub grab and put in,
do {
ImageBox1.Image = capture.QueryFrame();
} while (true);
Cheers
Shreyas
Call QueryFrame() twice, it works for me:
if (capture == null)
capture = new Capture();
capture.QueryFrame();
Image<Bgr,Byte> img=capture.QueryFrame().ToImage<Bgr, Byte>();
imageBox1.Image = img.Bitmap;
In my case Kaspersky AntiVirus was blocking the access to my webcam. After changing some security settings I was able to get emgu capture back working.