Access violation when streaming video with emgu opencv - opencv

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.CV.Structure;
namespace CrackleTest
{
public static class Controller
{
public static Capture capture = new Capture();
public static VideoWriter CaptureOutput;
public static void Init()
{
capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1920);
capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1080);
CaptureOutput = new VideoWriter
(
"output.avi",
-1, //CvInvoke.CV_FOURCC("W","M","V","1"),
30, //fps
(int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH),
(int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT),
true
);
capture.ImageGrabbed += SaveFrame;
capture.Start();
}
public static void Stop()
{
capture.Stop();
CaptureOutput.Dispose();
}
public static void SaveFrame(Object sender, EventArgs e)
{
Image<Bgr, Byte> video = capture.RetrieveBgrFrame();
CaptureOutput.WriteFrame(video);
}
}
}
When I call the stop function I get an error message
An unhandled exception of type 'System.AccessViolationException'
occurred in Emgu.CV.dll
Additional information: Attempted to read or write protected memory.
This is often an indication that other memory is corrupt.
I'm not sure what the best practices are for streaming video from usb webcam in opencv.

Related

Unity app crashes when built for iOS with camera enabled

I have an app which uses zxing to scan qr codes in the app. However when I build the app with these scripts in the scene the app crashes on startup. I thought it was something in the Awake() or Start() but I've wrapped those methods in a try catch, and even then I'm not getting any errors, and it doesn't crash on android and in the editor.
I don't have access to a Mac, and am using Unity Cloud Build to build it.
I also don't know how to enable permissions, I thought I did when creating the .p12 file, but I've also found that there's an info.plist file that I have to request permissions with.
Prior research I found this Unity Question about adding items to the Xcode project but not only did including the xcodeapi give me errors, but the using statements didn't work.
There are two scripts
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
public class WebCamController : MonoBehaviour {
public int desiredWidth = 1280;
public int desiredHeight = 720;
public int desiredFPS = 60;
public RawImage output;
[HideInInspector]
public WebCamTexture webcamTexture;
void Start ()
{
webcamTexture = new WebCamTexture(desiredWidth, desiredHeight, desiredFPS);
output.texture = webcamTexture;
Play();
}
public void Play()
{
webcamTexture.Play();
}
public void Pause()
{
webcamTexture.Stop();
}
}
and
using UnityEngine;
using System.Collections;
using ZXing;
using ZXing.QrCode;
using ZXing.Common;
using System;
public class CodeScanner : MonoBehaviour {
private static CodeScanner _instance;
public static CodeScanner Instance
{
get
{
if(null == _instance)
{
Debug.Log("Code Scanner Instance not found");
}
return _instance;
}
}
[Header("References")]
public WebCamController wcc;
[Header("Properties")]
private BarcodeReader codeScanner;
private string lastScanned = "";
public delegate void Found(string text, string type);
public event Found OnCodeScanned;
private bool active;
public void Awake()
{
_instance = this;
}
void Start () {
codeScanner = new BarcodeReader();
StartCoroutine(ReadCode());
wcc.Play();
}
IEnumerator ReadCode()
{
while (active)
{
try
{
var data = codeScanner.Decode(wcc.webcamTexture.GetPixels32(), wcc.webcamTexture.width, wcc.webcamTexture.height);
if (data != null)
{
//if (data.Text != lastScanned)
//{
OnCodeScanned(data.Text, data.BarcodeFormat.ToString());
//}
lastScanned = data.Text;
}
}
catch(Exception e)
{
}
yield return new WaitForSeconds(1.0f);
}
}
public void Activate()
{
wcc.Play();
active = true;
StartCoroutine(ReadCode());
}
public void Stop()
{
active = false;
wcc.Pause();
}
}
My device is added properly to the .p12 certificate I can compile and run the program without these scripts in the scene.

.DismissModalViewController closes all my pages. Why?

I am using an image picker in my xamarin forms in order to pick an image from gallery to my program...
But, only in IOS device, when I close the image picker using
imagePicker.DismissModalViewController(true);
all my pop ups that is opened are closed with the imagePicker...
Does someone know why? or how I can solve that?
I am using DependencyService to do that in both
This is the code in IOS project
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Foundation;
using UIKit;
using neoFly_Montana.iOS;
using Xamarin.Forms;
using neoFly_Montana.Interface;
using System.Threading.Tasks;
using System.IO;
[assembly: Dependency(typeof(PicturePickerImplementation))]
namespace neoFly_Montana.iOS
{
public class PicturePickerImplementation : IPicturePicker
{
TaskCompletionSource<Stream> taskCompletionSource;
UIImagePickerController imagePicker;
public Task<Stream> GetImageStreamAsync()
{
// Create and define UIImagePickerController
imagePicker = new UIImagePickerController
{
SourceType = UIImagePickerControllerSourceType.PhotoLibrary,
MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary)
};
// Set event handlers
imagePicker.FinishedPickingMedia += OnImagePickerFinishedPickingMedia;
imagePicker.Canceled += OnImagePickerCancelled;
// Present UIImagePickerController;
UIWindow window = UIApplication.SharedApplication.KeyWindow;
var viewController = window.RootViewController;
viewController.PresentModalViewController(imagePicker, true);
// Return Task object
taskCompletionSource = new TaskCompletionSource<Stream>();
return taskCompletionSource.Task;
}
void OnImagePickerFinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs args)
{
UIImage image = args.EditedImage ?? args.OriginalImage;
if (image != null)
{
// Convert UIImage to .NET Stream object
NSData data = image.AsJPEG(1);
Stream stream = data.AsStream();
// Set the Stream as the completion of the Task
taskCompletionSource.SetResult(stream);
}
else
{
taskCompletionSource.SetResult(null);
}
imagePicker.DismissModalViewController(true);
}
void OnImagePickerCancelled(object sender, EventArgs args)
{
taskCompletionSource.SetResult(null);
imagePicker.DismissModalViewController(true);
}
}
}
I am using RG.PLUGIN.POPUP

Available Wifi connections list by using list view in Xmamrin

i just want to know that if it is possible to make listview for the available wifi connections by using xamarin.....And if it is possible then please help me out here...... step by step.
Yes, It is. took it from xamarin forum: https://forums.xamarin.com/discussion/27364/how-to-get-list-of-wifi-networks
using Android.Content;
using Android.Net.Wifi;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace NetworkLocation.Utility
{
public class Wifi
{
private Context context = null;
private static WifiManager wifi;
private WifiReceiver wifiReceiver;
public static List<string> WiFiNetworks;
public Wifi(Context ctx)
{
this.context = ctx;
}
public void GetWifiNetworks()
{
WiFiNetworks = new List<string>();
// Get a handle to the Wifi
wifi = (WifiManager)context.GetSystemService(Context.WifiService);
// Start a scan and register the Broadcast receiver to get the list of Wifi Networks
wifiReceiver = new WifiReceiver();
context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction));
wifi.StartScan();
}
class WifiReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
IList<ScanResult> scanwifinetworks = wifi.ScanResults;
foreach(ScanResult wifinetwork in scanwifinetworks)
{
WiFiNetworks.Add(wifinetwork.Ssid);
}
}
}
}
}

How to Get GPS base on Wifi using Xamarin

This code base on the link below:
http://docs.xamarin.com/guides/android/platform_features/maps_and_location/part_3_-_location_services
I could not get any Lat/Lon ( Gps/Wifi)
The code is below :
I have added:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
&lt:uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Android.Locations
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
//-- add these
using Android.Locations;
using System.Collections.Generic;
using System.Threading;
using System.Text;
using System.Linq;
using System.Xml;
namespace GPSWifi
{
[Activity (Label = "GPSWifi", MainLauncher = true)]
public class Activity1 : Activity
{
int count = 1;
private LocationManager _locMgr;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
InitializeLocationManager();
}
private void InitializeLocationManager()
{
_locMgr = (LocationManager) GetSystemService(LocationService);
var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.NoRequirement;
locationCriteria.PowerRequirement = Power.NoRequirement;
string locationProvider = _locMgr.GetBestProvider(locationCriteria, true);
_locMgr.RequestLocationUpdates (locationProvider, 2000, 1, this);
}
protected override void OnResume ()
{
base.OnResume ();
_locMgr.RequestLocationUpdates (LocationManager.GpsProvider, 2000, 1, this);
}
protected override void OnPause ()
{
base.OnPause ();
_locMgr.RemoveUpdates (this);
}
public void OnProviderDisabled(string provider) {}
public void OnProviderEnabled(string provider) {}
public void OnLocationChanged (Location location)
{
var locationText = FindViewById<TextView>(Resource.Id.locationTextView);
locationText.Text = String.Format ("Latitude = {0}, Longitude = {1}",
location.Latitude, location.Longitude);
}
}
}
Your help is much appreciated.
-- Error Message :
C:\Program Files
(x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2,2):
Error MSB4018: The "Aapt" task failed unexpectedly.
System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at Xamarin.Android.Tasks.BuildToolsUtils.GetBuildToolsPath(String
androidSdkDirectory)
at Xamarin.Android.Tasks.Aapt.GenerateFullPathToTool()
at Microsoft.Build.Utilities.ToolTask.ComputePathToTool()
at Microsoft.Build.Utilities.ToolTask.Execute()
at Xamarin.Android.Tasks.Aapt.Execute()
at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at
Microsoft.Build.BackEnd.TaskBuilder.d__20.MoveNext()
(MSB4018) (GPSWifi)
This error: The "Aapt" task failed unexpectedly. has just started occurring recently - I think it's to do with the very latest sdk's from Android/Google - I think they've moved a file location.
Check other questions like Xamarin Studio 2 - latest stable update - Error executing task Aapt: The source sequence is empty
Then check with Xamarin support - they'll issue an update to fix this.

CK30: After using BarcodeReader() my keyboard stops working

I`m developing for a Intermec handheld device CK30 with a 2D reader in C# compact framework 2.0 (windows mobile 6.1).
Everytime I use barcode mey keyboard stops working. Any ideas why?
Heres the code. The first section is a class that configures the barcode reader. The second section is a form that uses the barcode reader to fill a textbox.
After reading something with the barcode reader the keyboard stops working...
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Intermec.DataCollection;
namespace BarCodeReaderTest
{
class LeitorCodigoDeBarras
{
public BarcodeReader LerCodigoDeBarras()
{
try
{
BarcodeReader meuLeitor = new BarcodeReader("default", 4096);
meuLeitor.ScannerEnable = true;
meuLeitor.ThreadedRead(true);
return meuLeitor;
}
catch (BarcodeReaderException bx)
{
MessageBox.Show("Não foi possível inicializar o leitor de código de barras. Contate seu supervisor. \n" + bx.Message);
return null;
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Intermec.DataCollection;
namespace BarCodeReaderTest
{
public partial class Form1 : Form
{
public BarcodeReader leitor;
public Form1()
{
InitializeComponent();
LeitorCodigoDeBarras classeLeitor = new LeitorCodigoDeBarras();
leitor = classeLeitor.LerCodigoDeBarras();
leitor.BarcodeRead += new BarcodeReadEventHandler(this.eventoLeitorCodigoDeBarras);
}
void eventoLeitorCodigoDeBarras(object sender, BarcodeReadEventArgs e)
{
tbCodLido.Text = e.strDataBuffer;
}
}
}
OK, I now relaized that you are using the BarcodeReader within a separate class.
Please try the follwing, standard, example (one listbox and one button in form):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Intermec.DataCollection;
namespace BarcodeReader
{
public partial class Form1 : Form
{
private Intermec.DataCollection.BarcodeReader bcr;
public Form1()
{
InitializeComponent();
bcr = new Intermec.DataCollection.BarcodeReader();
bcr.BarcodeRead += new BarcodeReadEventHandler(bcr_BarcodeRead);
bcr.ThreadedRead(true);
}
void bcr_BarcodeRead(object sender, BarcodeReadEventArgs bre)
{
this.listBox1.Items.Add(bre.strDataBuffer);
}
}
private void btnExit_Click(object sender, EventArgs e)
{
if (bcr !=null)
{
bcr.Dispose();
}
Application.Exit();
}
}
If that works (see also the examples coming with the Intermec Datacollection resource kit), we can examine, why you construct does not work. I assume you have the latest DataCollection Resource Kit installed.

Resources