gearmat
Messages postés12Date d'inscriptionmercredi 30 juillet 2008StatutMembreDernière intervention31 août 2010
-
16 avril 2010 à 18:57
gearmat
Messages postés12Date d'inscriptionmercredi 30 juillet 2008StatutMembreDernière intervention31 août 2010
-
19 avril 2010 à 12:41
salut a tous,
Je suis entrain de coder une appli pour faire la lecture de code barre via webcam
j'utilise la librairie directX.capture pour capturer les images et Zxing pour les décoder
j'ai un problème je veux prendre une image toutes les 100ms faire une détection et décoder si il y a un code dans l'image. j'utilise un thread mais ca ne marche.
je le fait via un bouton et ca marche très bien. avez vous une autre méthode que le thread
ps : je suis novice
using System;
using System.Data;
using System.Text;
using System.Drawing;
using DirectX.Capture;
using System.Windows.Forms;
using System.Timers;
using System.ComponentModel;
using System.Collections.Generic;
using com.google.zxing.multi;
using com.google.zxing.common;
using com.google.zxing.qrcode.detector;
using com.google.zxing;
using System.Threading;
namespace test
{
public partial class Form1 : Form
{
private Filters InputOptions = new Filters();
public Thread fullcapturepdecode;
public Capture captureVX = null;
public Form1()
{
InitializeComponent();
Camopen();
fullcapturepdecode = new Thread(new ThreadStart(capturendecode));
}
public void capturendecode()
{
while (Thread.CurrentThread.IsAlive)
{
try
{
prendunefram();
//decodeunefram();
}
catch (Exception exept)
{
this.ErrorMessage(exept);
}
}
}
private void ErrorMessage(Exception e)
{
MessageBox.Show(e.Message, "Webcam Test", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void button1_Click(object sender, EventArgs e)
{
fullcapturepdecode.Start();
}
private void prendunefram()
{
try
{
captureVX.CaptureFrame();
}
catch (Exception exept)
{
this.ErrorMessage(exept);
}
}
gearmat
Messages postés12Date d'inscriptionmercredi 30 juillet 2008StatutMembreDernière intervention31 août 2010 16 avril 2010 à 18:59
erreur
L'exception System.InvalidCastException n'a pas été gérée
Message="Impossible d'effectuer un cast d'un objet COM de type 'System.__ComObject' en type d'interface 'DShowNET.ISampleGrabber'. Cette opération a échoué, car l'appel QueryInterface sur le composant COM pour l'interface avec l'IID '{6B652FFF-11FE-4FCE-92AD-0266B5D7C78F}' a échoué en raison de l'erreur suivante : Cette interface n'est pas prise en charge (Exception de HRESULT : 0x80004002 (E_NOINTERFACE))."
Source="DShowNET"
StackTrace:
à DShowNET.ISampleGrabber.SetCallback(ISampleGrabberCB pCallback, Int32 WhichMethodToCallback)
à DirectX.Capture.Capture.CaptureFrame()
à test.Form1.prendunefram() dans T:\Visual Studio 2008\Projects\test\test\Form1.cs:ligne 82
à test.Form1.capturendecode() dans T:\Visual Studio 2008\Projects\test\test\Form1.cs:ligne 47
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
InnerException:
Lutinore
Messages postés3246Date d'inscriptionlundi 25 avril 2005StatutMembreDernière intervention27 octobre 201241 17 avril 2010 à 14:55
Salut, apparemment ta classe de capture ne supporte pas d'être appellée depuis un autre thread, essaye depuis un System.Windows.Forms.Timer ou depuis un thread MTA :