I've got a little problem with ZXing.net... I dosen't work !
Maybe I use it incorrectly, but I search, search, search, nothing seems to work... I use WindowsForms. I want to read my QR Code thought my camera. I use another library called AForge. This one works perfectly ; My camera shows up and works like a charm ! But when I want to read a QR Code, it dosen't work...
So maybe someone will be able to help me ... ?
//When I load my form, I start the camera
private void FrmConnexion_Load(object sender, EventArgs e)
{
// enumerate video devices
videoSources = new FilterInfoCollection(FilterCategory.VideoInputDevice);
// create video source
videoStream = new VideoCaptureDevice(videoSources[0].MonikerString);
// set NewFrame event handler
videoStream.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
// start the video source
videoStream.Start();
}
//Every new frame of the video
void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
try
{
streamBitmap = (Bitmap)eventArgs.Frame.Clone();
safeTempstreamBitmap = (Bitmap)streamBitmap.Clone();
Pic_Camera.Image = streamBitmap;
Pic_Camera.Refresh();
//Where I decome my QR Code.
Result result = barcodeReader.Decode(streamBitmap);
//To see my result, I register my result into a Label.
Lbl_Identifiant.Text = "{result?.Text}";
}
catch (Exception exp)
{
Console.Write(exp.Message);
}
}
I think I didn't forget anything..
Thanks for your help !
Related
I am trying to take a picture using Camera class from Android.Hardware. I am getting the feed and the camera is getting auto-foucs. The problem is that I do not know how to take the photo.
_camera = Camera.Open();
Camera.Parameters param = _camera.GetParameters();
param.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
_camera.SetParameters(param);
var previewSize = _camera.GetParameters().PreviewSize;
_textureView.LayoutParameters =
new FrameLayout.LayoutParams(previewSize.Width,
previewSize.Height, GravityFlags.Center);
try
{
_camera.SetPreviewTexture(surface);
_camera.StartPreview();
}
catch (Java.IO.IOException ex)
{
System.Console.WriteLine(ex.Message);
}
// this is the sort of thing TextureView enables
_textureView.Rotation = 90.0f;
This link may help you on this https://developer.xamarin.com/recipes/android/other_ux/camera_intent/take_a_picture_and_save_using_camera_app/
But you may use this code for taking picture (TakeAPicture).
private void TakeAPicture (object sender, EventArgs eventArgs)
{
Intent intent = new Intent (MediaStore.ActionImageCapture);
App._file = new File (App._dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));
intent.PutExtra (MediaStore.ExtraOutput, Uri.FromFile (App._file));
StartActivityForResult (intent, 0);
}
Happy Coding! :)
The TakePicture-method is the one you are looking for. To use this you need to implement some interfaces. Especially the IPictureCallback to receive the picture in OnPictureTaken.
A sample implementation would look like this:
public void OnPictureTaken(byte[] data, Android.Hardware.Camera camera)
{
camera.StopPreview();
Toast.MakeText(this, "Cheese", ToastLength.Short).Show();
camera.StartPreview();
}
To prevent that the app hangs you need to stop the preview and (re-)start it again.
I have created a MediaElement in my Windows Phone 8.1 app, and I am trying to play an mp4 video. When I press the button to play the video, it shows the video's first frame (splash screen), but it never goes beyond that, and it looks like a still picture. What could I be doing wrong? I don't get any error from my MediaFailed method, either.
private void openButton_Click(object sender, RoutedEventArgs e)
{
shakeImage.Visibility = Visibility.Collapsed;
timer.Stop();
timerReset.Stop();
rotateImage.Stop();
mediaElement.Stop();
Uri explosion = new Uri(BaseUri, "Explode.mp4");
mediaElement.Source = explosion;
mediaElement.Play();
mediaElement.MediaFailed += mediaElement_MediaFailed;
}
void mediaElement_MediaFailed)object sender, ExceptionRoutedEventArgs e)
{
throw new FileNotFoundException();
}
if you are playing audio file from your phone you should change "UriKind " to "Relative" like this
Uri explosion = new Uri( "Explode.mp4",UriKind.RelativeOrAbsolute);
// or you could use this way
Stream stream = isoStore1.OpenFile("Explode.mp4", System.IO.FileMode.Open, System.IO.FileAccess.Read );
this.mediaElement.Stop();
this.mediaElement.SetSource(stream);
mediaElement.Play();
stream.Close();
Turns out it was due to Windows Phone 8 being picky about file formats and not throwing errors even though they were incorrect. I converted it to a certain wmv type and it seems to work now.
How to upload or add an Image to UIImageView directly from iPhone/Ipad Captured camera Image.
I have uploaded an image to UIImageView from photo library.
Now, I want upload an image directly after taken an image through camera to ImageView.
Please suggest me how to implement this.
using IOS 8.0
This can be accomplished very easily with the Xamarin.Mobile component, which is free and works with all platforms.
http://components.xamarin.com/view/xamarin.mobile
From the example they give:
using Xamarin.Media;
// ...
var picker = new MediaPicker ();
if (!picker.IsCameraAvailable)
Console.WriteLine ("No camera!");
else {
try {
MediaFile file = await picker.TakePhotoAsync (new StoreCameraMediaOptions {
Name = "test.jpg",
Directory = "MediaPickerSample"
});
Console.WriteLine (file.Path);
} catch (OperationCanceledException) {
Console.WriteLine ("Canceled");
}
}
After you take the picture, it is saved to the directory you specified, with the name you specified. To easily retrieve this picture and display it with your ImageView using the above example you can do the following:
//file is declared above as type MediaFile
UIImage image = new UIImage(file.Path);
//Fill in with whatever your ImageView is
yourImageView.Image = image;
Edit:
Just a note that the above needs to be asynchronous. So if you want to launch the camera from a button call, for instance, you just slightly modify the .TouchUpInside event:
exampleButton.TouchUpInside += async (object sender, EventArgs e) => {
//Code from above goes in here, make sure you have async after the +=
};
Otherwise you could wrap the code from above in a function and add async to that:
public async void CaptureImage()
{
//Code from above goes here
}
You will need to use AVFoundation to do this. Check out the AVCam sample project in Xcode:
https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html
In my C# project I want to play a sound with a specified start- and end time.
I used the System.Media.SoundPlayer with the .Play() function. But with this function I can only play the whole sound file or can abort it after I have counted the runtime.
In fact I want to say, that the given sound file should start for example at time 1m:25s:30ms and should end at time 1m:50s:00ms or after a duration of 10s or so.
Does anybody know a simple solution for his problem?
Thanks 4 help.
Not really an answer, but this question got me wondering if you can do something like this:
long startPositionInBytes = 512;
long endPositionInBytes = 2048;
using ( var audioStream = File.OpenRead(#"audio.wav") )
{
audioStream.Position = startPositionInBytes;
using ( var player = new SoundPlayer(audioStream) )
{
player.Play();
do
{
Thread.Sleep(1);
} while ( audioStream.Position <= endPositionInBytes );
player.Stop();
}
}
In case you want to play a Background Media Player (for e.g., an audio file) which would start from a specific time and would work for a certain duration, then this code snippet could also be useful:
StorageFile mediaFile = await KnownFolders.VideosLibrary.GetFileAsync(fileName);//the path
BackgroundMediaPlayer.Current.SetFileSource(mediaFile);
BackgroundMediaPlayer.Current.Position = TimeSpan.FromMilliseconds(3000/*enter the start time here*/);
BackgroundMediaPlayer.Current.Play();
await Task.Delay(TimeSpan.FromMilliseconds(10000/*for how long you want to play*/));
BackgroundMediaPlayer.Shutdown();//stops the player
**But this would only work for Windows 8.1 and above.
For more information, click here...
In the End I use the NAudio library. That can handle this - not in a perfect way but ok.
see https://stackoverflow.com/a/13372540/2936206
I got it to work by using Windows Media Player in a C sharp program with a timer control and an open dialog.
I followed a sample that used buttons on the form and made the media player invisible.
After opening the file with an Open button that used the open dialog to open the mp3 file, on the Play button I put this code [the end effect is that it started the file in position 28.00 and ended it in position 32.50]:
private void button2_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = openFileDialog1.FileName;
timer1.Start();
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 28.00;
axWindowsMediaPlayer1.Ctlcontrols.play();
}
Then in the timer tick event:
private void timer1_Tick(object sender, EventArgs e)
{
if (axWindowsMediaPlayer1.Ctlcontrols.currentPosition >= 32.50)
{ axWindowsMediaPlayer1.Ctlcontrols.pause(); }
label1.Text = String.Format("{0:0.00}",
axWindowsMediaPlayer1.Ctlcontrols.currentPosition);
}
I´m using class Capture from EmguCV to take images from a WebCam.
According to the documentation of the class (http://www.emgu.com/wiki/files/2.0.0.0/html/18b6eba7-f18b-fa87-8bf2-2acff68988cb.htm), Capture has 3 constructors.
Using public Capture() its supposed to use the default camera and it works properly.
As I saw in one of the examples, seems that
public Capture(string fileName) //takes a video file as the source for the captures.
The last constructor is
public Capture(int camIndex) //which is supposed to "Create a capture using the specific camera"
I tried to use this last constructor to allow the user to choose the device in case he has more than one camera (for example, the integrated camera in a laptop or a USB cam pluged in)
My problem is I don´t know how to get a list of available devices. Tried to create captures with index from 0 to 99 and try to grab a frame expecting an exception, but it just takes a black image with the 100 captures. Also, when I use the default camera, I don´t know how to get his index.
Any help?
Edit: With the info in the answer of Shiva I got it working with this (I post it for future references):
private void onLoad(object sender, RoutedEventArgs e)
{
//Add the image processing to the dispatcher
this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(dispatcherTimer_Tick);
//Get the information about the installed cameras and add the combobox items
DsDevice[] _SystemCamereas = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
Video_Device[] WebCams = new Video_Device[_SystemCamereas.Length];
for (int i = 0; i < _SystemCamereas.Length; i++)
{
WebCams[i] = new Video_Device(i, _SystemCamereas[i].Name, _SystemCamereas[i].ClassID); //fill web cam array
ComboBoxDevices.Items.Add(WebCams[i].ToString());
}
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
if (capture != null)
{
//Capture an image
Image<Bgr, byte> img = capture.QueryFrame();
//Show the image in the window
ImageOriginal.Source = ImageProcessor.ToBitmapSource(img);
}
}
private void ComboBoxDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//If there is already a capture, dispose it
if (capture != null)
{
capture.Dispose();
}
//Get the selected camera
int selectedDevice = ComboBoxDevices.SelectedIndex;
try
{
//Create new capture with the selected camera
capture = new Capture(selectedDevice);
}
catch (Exception excpt)
{
MessageBox.Show(excpt.Message);
}
}
The capture object can be used to give static files as input using the following code
Capture grabber = new Emgu.CV.Capture(#".\..\..\file.avi");//can be relative path or absolute path of the video file.
For finding the list of connected web cams will need to import something like Direct Show (DirectShow.Net.dll) into the project and use the following code to retrieve the list of connected web cams .
DsDevice[] _SystemCamereas = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
Video_Device[] WebCams = new Video_Device[_SystemCamereas.Length];
for (int i = 0; i < _SystemCamereas.Length; i++)
{
WebCams[i] = new Video_Device(i, _SystemCamereas[i].Name, _SystemCamereas[i].ClassID); //fill web cam array
Camera_Selection.Items.Add(WebCams[i].ToString());
}
Check this link for the full code
http://www.emgu.com/wiki/index.php?title=Camera_Capture
This list can be populated into a combo box and each connected device can be chosen to retrieve the video input from the specific device.
Example can be found here:
http://fewtutorials.bravesites.com/entries/emgu-cv-c/level-2---use-multiple-cameras-in-one-application.
For your last question the Default Camera always has the index of 0.
So for initializing the Capture Object with default camera you will have to use the following code
Capture grabber = new Emgu.CV.Capture(0);
Examining the EMGU CV source seems to indicate that it's just passing the index off to the underlying OpenCV library, as part of the cvCreateCameraCapture (int index) function. That function is... A bit of a mess of #ifdefs, but from what I can see (and from what the comments indicate), the index is used to specify both the camera you want, and the API it should be using.
Try successively trying multiples of a hundred; each should use a different codec, attempting to use the first camera. It may be that you have one of the APIs listed compiled into your copy of OpenCV, but not working correctly on your system.
Edit: Drilling down further, it seems like it ends up at this function call, which uses the MFEnumDeviceSources function to get the list. The device you wanted is then returned out of that list (see the getDevice function a few lines higher up). So, it looks to me like the dialog you mentioned in your comment is part of Windows' MediaFoundation stuff, in which case you might want to google the wording of the message, see if some people with more experience with MF can point you in the right direction.