// Use this for initialization void Start() { Image <Bgr, Byte> img = new Image <Bgr, byte>(640, 240); String openclStr = "None"; if (CvInvoke.HaveOpenCL) { //StringBuilder builder = new StringBuilder(); using (VectorOfOclPlatformInfo oclPlatformInfos = OclInvoke.GetPlatformInfo()) { if (oclPlatformInfos.Size > 0) { OclPlatformInfo platformInfo = oclPlatformInfos[0]; openclStr = platformInfo.ToString(); } } } CvInvoke.PutText(img, String.Format("Emgu CV for Unity {0}", Emgu.Util.Platform.OperationSystem), new System.Drawing.Point(10, 60), Emgu.CV.CvEnum.FontFace.HersheyDuplex, 1.0, new MCvScalar(0, 255, 0)); CvInvoke.PutText(img, String.Format("OpenCL: {0}", openclStr), new System.Drawing.Point(10, 120), Emgu.CV.CvEnum.FontFace.HersheyDuplex, 1.0, new MCvScalar(0, 0, 255)); Texture2D texture = TextureConvert.ImageToTexture2D(img, FlipType.Vertical); this.GetComponent <GUITexture>().texture = texture; this.GetComponent <GUITexture>().pixelInset = new Rect(-img.Width / 2, -img.Height / 2, img.Width, img.Height); }
public void TestOclChangeDefaultDevice() { using (VectorOfOclPlatformInfo oclPlatformInfos = OclInvoke.GetPlatformsInfo()) { if (oclPlatformInfos.Size > 0) { for (int i = 0; i < oclPlatformInfos.Size; i++) { OclPlatformInfo platformInfo = oclPlatformInfos[i]; for (int j = 0; j < platformInfo.DeviceNumber; j++) { OclDevice device = platformInfo.GetDevice(j); Trace.WriteLine(String.Format("{0}Setting device to {1}", Environment.NewLine, device.Name)); //OclDevice d = new OclDevice(); //d.Set(device.NativeDevicePointer); OclDevice defaultDevice = OclDevice.Default; defaultDevice.Set(device.NativeDevicePointer); Trace.WriteLine(String.Format("Current OpenCL default device: {0}", defaultDevice.Name)); UMat m = new UMat(2048, 2048, DepthType.Cv8U, 3); m.SetTo(new MCvScalar(100, 100, 100)); CvInvoke.GaussianBlur(m, m, new Size(3, 3), 3); Stopwatch watch = Stopwatch.StartNew(); m.SetTo(new MCvScalar(100, 100, 100)); CvInvoke.GaussianBlur(m, m, new Size(3, 3), 3); watch.Stop(); Trace.WriteLine(String.Format("Device '{0}' time: {1} milliseconds", defaultDevice.Name, watch.ElapsedMilliseconds)); CvInvoke.OclFinish(); } } } Trace.WriteLine(Environment.NewLine + "Disable OpenCL"); CvInvoke.UseOpenCL = false; UMat m2 = new UMat(2048, 2048, DepthType.Cv8U, 3); m2.SetTo(new MCvScalar(100, 100, 100)); CvInvoke.GaussianBlur(m2, m2, new Size(3, 3), 3); Stopwatch watch2 = Stopwatch.StartNew(); m2.SetTo(new MCvScalar(100, 100, 100)); CvInvoke.GaussianBlur(m2, m2, new Size(3, 3), 3); watch2.Stop(); Trace.WriteLine(String.Format("CPU time: {0} milliseconds", watch2.ElapsedMilliseconds)); CvInvoke.UseOpenCL = true; } }
/// <summary> /// Create the standard vector of OclPlatformInfo /// </summary> public VectorOfOclPlatformInfo(MDMatch[][] values) : this() { using (OclPlatformInfo v = new OclPlatformInfo()) { for (int i = 0; i < values.Length; i++) { v.Push(values[i]); Push(v); v.Clear(); } } }
/// <summary> /// Convert the standard vector to arrays of int /// </summary> /// <returns>Arrays of int</returns> public MDMatch[][] ToArrayOfArray() { int size = Size; MDMatch[][] res = new MDMatch[size][]; for (int i = 0; i < size; i++) { using (OclPlatformInfo v = this[i]) { res[i] = v.ToArray(); } } return(res); }
/// <summary> /// Convert the standard vector to arrays of int /// </summary> /// <returns>Arrays of int</returns> public Rectangle[][] ToArrayOfArray() { int size = Size; Rectangle[][] res = new Rectangle[size][]; for (int i = 0; i < size; i++) { using (OclPlatformInfo v = this[i]) { res[i] = v.ToArray(); } } return(res); }
protected override View OnCreateDialogView() { LayoutInflater inflator = LayoutInflater.FromContext(this.Context); View dialog = inflator.Inflate(Resource.Layout.opencl_preference, null); _openCLRadioGroup = dialog.FindViewById <RadioGroup>(Resource.Id.opencl_preference_radio_group); AppPreference preference = new AppPreference(); RadioButton checkedButton = null; RadioButton cpuButton = new RadioButton(this.Context); cpuButton.Text = "CPU"; _openCLRadioGroup.AddView(cpuButton); //int selectedIdx = -1; if (preference.UseOpenCL == false) { checkedButton = cpuButton; } cpuButton.Click += (sender, args) => { preference.UseOpenCL = false; //Toast.MakeText(this.Context, "cpu clicked", ToastLength.Short).Show(); }; String selectedDeviceName = preference.OpenClDeviceName; if (selectedDeviceName == null && CvInvoke.HaveOpenCL && preference.UseOpenCL) { selectedDeviceName = OclDevice.Default.Name; } //int counter = 1; using (VectorOfOclPlatformInfo oclPlatformInfos = OclInvoke.GetPlatformsInfo()) { if (oclPlatformInfos.Size > 0) { for (int i = 0; i < oclPlatformInfos.Size; i++) { OclPlatformInfo platformInfo = oclPlatformInfos[i]; for (int j = 0; j < platformInfo.DeviceNumber; j++) { OclDevice device = platformInfo.GetDevice(j); RadioButton deviceButton = new RadioButton(this.Context); deviceButton.Text = "OpenCL: " + device.Name; if (preference.UseOpenCL == true && device.Name.Equals(selectedDeviceName)) { checkedButton = deviceButton; } _openCLRadioGroup.AddView(deviceButton); //counter++; deviceButton.Click += (sender, args) => { preference.UseOpenCL = true; preference.OpenClDeviceName = device.Name; //Toast.MakeText(this.Context, device.Name + " clicked", ToastLength.Short).Show(); }; } } } } if (checkedButton != null) { _openCLRadioGroup.Check(checkedButton.Id); } //_openCLRadioGroup.in /* * _openCLToggleButton.Checked = preference.UseOpenCL; * * _openCLToggleButton.CheckedChange += (sender, args) => * { * bool isChecked = args.IsChecked; * * if (isChecked && !CvInvoke.HaveOpenCL) * { * _openCLToggleButton.Checked = false; * Toast.MakeText(Context, "No OpenCL compatible device found.", ToastLength.Long).Show(); * isChecked = false; * } * * preference.UseOpenCL = isChecked; * }; */ return(dialog); }
/// <summary> /// Push a value into the standard vector /// </summary> /// <param name="value">The value to be pushed to the vector</param> public void Push(OclPlatformInfo value) { VectorOfOclPlatformInfoPush(_ptr, value.Ptr); }