Im using xamarin.forms.maps and successfully getting the polyline but I want to get some patterns on it as here and not able to achieve it.
Can anyone please help me in solving this issue and my code is as below :
formsMap.DrawPolyLine = () =>
{
if (nativeMaps == null)
{
nativeMaps = Control as MKMapView;
}
nativeMaps.OverlayRenderer = GetOverlayRenderer;
CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[IOSMapViewModel.DeviceTrackData.Count];
int index = 0;
foreach (var position in IOSMapViewModel.DeviceTrackData)
{
coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
index++;
}
routeOverlay = MKGeodesicPolyline.FromCoordinates(coords);
if (nativeMap.Overlays != null)
nativeMaps.RemoveOverlays(nativeMap.Overlays);
IMKOverlay overlay = routeOverlay;
nativeMaps.AddOverlay(routeOverlay, MKOverlayLevel.AboveLabels);
};
nativeMap.GetViewForAnnotation = GetViewForAnnotation;
nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
}
}
MKOverlayRenderer GetOverlayRenderer(MKMapView mapView, IMKOverlay overlayWrapper)
{
if (polylineRenderer == null && !Equals(overlayWrapper, null))
{
var overlay = Runtime.GetNSObject(overlayWrapper.Handle) as IMKOverlay;
Foundation.NSNumber[] dashValues = { 3, 6 };
polylineRenderer = new MKPolylineRenderer(overlay as MKGeodesicPolyline)
{
FillColor = UIColor.Orange,
StrokeColor = UIColor.Orange,
LineWidth = 3,
Alpha = 1f,
LineDashPattern = dashValues
};
//polylineRenderer.CreatePath();
}
return polylineRenderer;
}
Related
My goal is to create a chart that will sit inside of a panel restricting it's size.
I managed to achieve this some time ago but today I noticed that the chart was growing inside of the panel, not allowing the data to be seen.
I have attached a picture bellow which should help understand the issue.
UPDATE
I noticed that if I rmeove 'bottom' from the Anchor property of the panel the chart does not exceed the parent panel but it does not increase with the change of the form which is what I'm looking for.
I also noticed that there was also another chart on the form that was exceeding the parent form, this time the chart would extend to the right not allowing to see the data.
This is the code that generates this second chart and places is inside of the parent panel.
panel_chart.Controls.Clear();
chart1 = new Chart();
chart1.MouseMove += chart1_MouseMove;
chart1.ChartAreas.Add(new ChartArea("chartArea1"));
chart1.Series.Clear();
chart1.Titles.Clear();
var serieOEE = new Series("OEE");
serieOEE.ChartType = SeriesChartType.Line;
serieOEE.XValueType = ChartValueType.String;
var serieProd = new Series("Prod");
serieProd.ChartType = SeriesChartType.Column;
serieProd.XValueType = ChartValueType.String;
var serieDisp = new Series("Disp");
serieDisp.ChartType = SeriesChartType.Column;
serieDisp.XValueType = ChartValueType.String;
var serieQual = new Series("Qual");
serieQual.ChartType = SeriesChartType.Column;
serieQual.XValueType = ChartValueType.String;
DateTime DataReg = DateTime.MinValue;
List<AreaOEE> listaChart = new List<AreaOEE>();
foreach (var item in ListaGrafico) //listaOEE
{
if (item.Designacao == DesignacaoLista)
{
listaChart.Add(item);
}
}
listaChart = listaChart.OrderBy(a => a.IDReg).ToList();
DateTime DataUltimoReg = DateTime.MinValue;
int j = 0;
foreach (var item in listaChart)
{
string HoraGraf = Convert.ToDateTime(item.Hora).ToString("HH:mm");
if (j == 0 || j == listaChart.Count - 1 ||
Math.Abs(Convert.ToDateTime(item.Hora).Subtract(DataUltimoReg).TotalMinutes) >= 30)
{
serieOEE.Points.AddXY(HoraGraf, item.OEE);
serieProd.Points.AddXY(HoraGraf, item.Produtividade);
serieQual.Points.AddXY(HoraGraf, item.Qualidade);
serieDisp.Points.AddXY(HoraGraf, item.Disponibilidade);
DataUltimoReg = Convert.ToDateTime(item.Hora);
if (j == listaChart.Count - 2)
{
break;
}
}
j++;
}
//Adicionar o ultimo
foreach (var item in listaOEE)
{
if (item.Designacao == DesignacaoLista)
{
string sHora = "";
try
{
sHora = item.Hora.Substring(1, 5);
}
catch (Exception ex)
{
string sEx = ex.Message;
}
foreach (var itemOee in serieOEE.Points)
{
if (itemOee.AxisLabel == sHora)
{
itemOee.YValues[0] = item.OEE;
}
}
foreach (var itemP in serieProd.Points)
{
if (itemP.AxisLabel == sHora)
itemP.YValues[0] = item.Produtividade;
}
foreach (var itemD in serieDisp.Points)
{
if (itemD.AxisLabel == sHora)
itemD.YValues[0] = item.Disponibilidade;
}
foreach (var itemQ in serieQual.Points)
{
if (itemQ.AxisLabel == sHora)
itemQ.YValues[0] = item.Qualidade;
}
}
}
chart1.Series.Add(serieProd);
chart1.Series.Add(serieQual);
chart1.Series.Add(serieDisp);
chart1.Series.Add(serieOEE);
serieOEE.BorderWidth = 4;
chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
chart1.ChartAreas[0].AxisX.Interval = 1;
chart1.ChartAreas[0].AxisY.Minimum = 0;
chart1.ChartAreas[0].AxisY.Maximum = 140;
chart1.Legends.Clear();
chart1.Legends.Add(serieOEE.Legend);
chart1.Titles.Add(DesignacaoLista + " " + DataTitulo.ToString("dd-MM HH:mm"));
chart1.Titles[0].Font = new Font("Arial", 13, FontStyle.Bold);
chart1.Visible = true;
chart1.Dock = DockStyle.Fill;
panel_chart.Controls.Add(chart1);
you can change the size of Chart with Chart.Size:
Chart1.Size = new Size(1000, 200); //1000px * 200px
I want to add a dynamic micro chart to my application but it doesn't work. After a call from a method a value gets added and it makes a completely new micro chart for my chart to have the new values, but the change isn't visible in the app. So the old Values stayed and there is no new one. Thanks for helping me.
WeightList = new List<float>();
WeightList.Add(0);
WeightList.Add((float)74.3);
entries = new ChartEntry[30];
SyncArray();
private void SyncArray()
{
if (WeightList.Count != entries.Length)
{
entries = new ChartEntry[WeightList.Count];
}
for (int i = 0; i <= WeightList.Count - 1; i++)
{
if (i == WeightList.Count - 1 || i == 0)
{
entries[i] = new ChartEntry(WeightList[i]) { Label = "" + i, ValueLabel = "" + WeightList[i] };
}
else
{
entries[i] = new ChartEntry(WeightList[i]) { Label = "" + i };
}
}
chart = new LineChart() { Entries = entries, BackgroundColor = SKColors.Transparent };
Chart = chart;
}
public LineChart Chart
{
get => chart;
set => SetProperty(ref chart, value);
}
public float Weight
{
get => weight;
set
{
weight = value;
WeightList.Add(weight);
SyncArray();
}
}
Credits: #Jason
What to change:
private void SyncArray()
{
if (WeightList.Count != entries.Length)
{
entries = new ChartEntry[WeightList.Count];
}
for (int i = 0; i <= WeightList.Count - 1; i++)
{
if (i == WeightList.Count - 1 || i == 0)
{
entries[i] = new ChartEntry(WeightList[i]) { Label = "" + i, ValueLabel = "" + WeightList[i] };
}
else
{
entries[i] = new ChartEntry(WeightList[i]) { Label = "" + i };
}
}
Chart = new LineChart() { Entries = entries, BackgroundColor = SKColors.Transparent };
}
I got a problem related with the TaskCompletionSource object and the Dismiss function of an alert. This problem does not appear within the IOS version of the application
When the application sends an notification, two alerts with working functionality will show up when the user activates the application:
Authentication
Filling in a value.
However, when I enter the application I only get to see the authentication(because this alert is called first within the app) and the second alert never shows up. I already tried to override the Dismiss function and set the TaskCompletionSource object result to null, but this causes the same alert to appear an X times before the application crashes. Is there a way to repeat the TaskCompletionSource object so that I can see all the alerts? Or what kind of modifications do I need to make on the Dismiss function so that the TaskCompletionSource is completed once all the alerts are shown?
Android Fragment Example code:
public static readonly int AlertWidth = Device.Idiom == TargetIdiom.Phone ? 270 : 320;
class AlertDialogFragment : DialogFragment
{
public string Title;
public string Body;
public View Content;
public List<AlertButton> Buttons;
public TaskCompletionSource<object> tsc;
public Dialog AndroidCustomAlert(Activity activ)
{
Android.Views.LayoutInflater inflater = Android.Views.LayoutInflater.From(activ);
Android.Views.View view = inflater.Inflate(Resource.Layout.AlertDialogLayout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(activ);
builder.SetView(view);
Android.Widget.TextView title = view.FindViewById<Android.Widget.TextView>(Resource.Id.Login);
title.Text = Title;
Android.Widget.TextView body = view.FindViewById<Android.Widget.TextView>(Resource.Id.pincodeText);
body.Text = Body;
body.MovementMethod = new Android.Text.Method.ScrollingMovementMethod();
Android.Widget.EditText pincode = view.FindViewById<Android.Widget.EditText>(Resource.Id.pincodeEditText);
Android.Widget.Button btnPositive = view.FindViewById<Android.Widget.Button>(Resource.Id.btnLoginLL);
Android.Widget.Button btnNegative = view.FindViewById<Android.Widget.Button>(Resource.Id.btnClearLL);
Android.Widget.Button btnNeutral = view.FindViewById<Android.Widget.Button>(Resource.Id.btnNeutral);
if (Title.Contains("Time"))
{
Android.Views.View secondView = inflater.Inflate(Resource.Layout.TimePickerLayout, null);
builder.SetView(secondView);
btnPositive = secondView.FindViewById<Android.Widget.Button>(Resource.Id.btnLoginLL);
btnNegative = secondView.FindViewById<Android.Widget.Button>(Resource.Id.btnClearLL);
var tp = secondView.FindViewById<Android.Widget.TimePicker>(Resource.Id.timePicker1);
tp.SetIs24HourView((Java.Lang.Boolean)true);
//Positive button feedback
btnPositive.Text = Buttons.Last().Text;
btnPositive.Click += delegate
{
var car = (Xamarin.Forms.TimePicker)Content;
var ts = new TimeSpan(tp.Hour, tp.Minute, 0);
car.Time = ts;
CommandsForButtons(Buttons.Last());
};
//Negative button feedback
btnNegative.Text = Buttons.First().Text;
btnNegative.Click += delegate
{
CommandsForButtons(Buttons.First());
};
}
else if (Title.Contains("How are you"))
{
btnPositive.Visibility = Android.Views.ViewStates.Gone;
btnNegative.Visibility = Android.Views.ViewStates.Gone;
btnNeutral.Visibility = Android.Views.ViewStates.Visible;
pincode.Visibility = Android.Views.ViewStates.Gone;
var happySlider = view.FindViewById<Android.Widget.SeekBar>(Resource.Id.happinessSlider);
happySlider.SetProgress(5, false);
happySlider.Visibility = Android.Views.ViewStates.Visible;
btnNeutral.Text = Buttons.First().Text;
btnNeutral.Click += delegate
{
var car = (StackLayout)Content;
var layoutView = (Xamarin.Forms.AbsoluteLayout)car.Children[1];
var slider = (Slider)layoutView.Children[1];
var totalHappyValue = happySlider.Progress / 10;
slider.Value = totalHappyValue;
CommandsForButtons(Buttons.First());
};
}
else
{
//Checks if there are no buttons, and if there aren't any, creates a neutral one
if (Buttons == null || Buttons.Count == 0)
{
btnPositive.Visibility = Android.Views.ViewStates.Gone;
btnNegative.Visibility = Android.Views.ViewStates.Gone;
btnNeutral.Visibility = Android.Views.ViewStates.Visible;
pincode.Visibility = Android.Views.ViewStates.Gone;
Buttons = new List<AlertButton> {
new AlertButton {
Text = "Oké",
IsPreferred = true,
Action = () => false
}
};
btnNeutral.Text = Buttons.First().Text;
btnNeutral.Click += delegate
{
CommandsForButtons(Buttons.First());
};
}
if (Content == null)
{
pincode.Visibility = Android.Views.ViewStates.Gone;
}
//Positive button feedback
btnPositive.Text = Buttons.Last().Text;
btnPositive.Click += delegate
{
var test = (StackLayout)Content;
if (test != null)
{
var car = (Entry)test.Children[0];
car.Text = pincode.Text;
}
CommandsForButtons(Buttons.Last());
};
//Negative button feedback
btnNegative.Text = Buttons.First().Text;
btnNegative.Click += delegate
{
CommandsForButtons(Buttons.First());
};
}
return builder.Create();
}
public void CommandsForButtons(AlertButton button)
{
Func<Task> dismiss = null;
var command = new Command(async () =>
{
var ab = button;
var cont = true;
if (ab.Action != null)
cont = ab.Action();
if (ab.ActionAsync != null)
{
cont = cont && await ab.ActionAsync();
}
if (!cont)
{
await dismiss();
}
});
dismiss = async () =>
{
dismiss = async () => { };
await Task.Run(() =>
{
Dismiss();
tsc.SetResult(null);
});
Log.Debug("TSC", tsc.Task.Status.ToString());
};
command.Execute(this);
}
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
var test = AndroidCustomAlert(Activity);
test.SetCanceledOnTouchOutside(false);
return test;
}
public override void Dismiss()
{
base.Dismiss();
}
}
public async Task Show(string title, string body, View content, List<AlertButton> buttons)
{
var tcs = new TaskCompletionSource<object>();
var adf = new AlertDialogFragment
{
Title = title,
Body = body,
Content = content,
Buttons = buttons,
tsc = tcs
};
var FragmentManager = ((Activity)Forms.Context).FragmentManager;
FragmentTransaction ft = FragmentManager.BeginTransaction();
//Remove fragment else it will crash as it is already added to backstack
Fragment prev = FragmentManager.FindFragmentByTag("alert");
if (prev != null)
{
ft.Remove(prev);
}
ft.AddToBackStack(null);
adf.Show(ft, "alert");
await tcs.Task;
}
The methods:
await Authentication();
await UserCheck();
And the IOS code:
public static readonly int AlertWidth = Device.Idiom == TargetIdiom.Phone ? 270 : 320;
public async Task Show(string title, string body, View content, List<AlertButton> buttons)
{
if (buttons == null || buttons.Count == 0)
{
buttons = new List<AlertButton> {
new AlertButton {
Text = "Oké",
IsPreferred = true,
Action = () => false
}
};
}
Func<Task> dismiss = null;
var captionSize = (double)StyleKit.PhoneDarkLabelStyles.Caption.Setters.First(s => s.Property == Label.FontSizeProperty).Value;
var titleSize = (double)StyleKit.PhoneDarkLabelStyles.Title.Setters.First(s => s.Property == Label.FontSizeProperty).Value;
var top = new StackLayout {
Padding = new Thickness(15, 20, 15, 20),
Spacing = 3,
Children = {
new Label {
Text = title,
Style = StyleKit.PhoneDarkLabelStyles.Title,
FontSize = Math.Max(16, titleSize),
HorizontalTextAlignment = TextAlignment.Center
},
new Label {
Text = body,
Style = StyleKit.PhoneDarkLabelStyles.Body,
//FontSize = ,
FontSize = Math.Max(14, captionSize),
HorizontalTextAlignment = TextAlignment.Center
} ,
new ContentView {
Padding = new Thickness(0,5,0,-10),
VerticalOptions = LayoutOptions.EndAndExpand,
Content = content
}
}
};
var buttonViews = buttons.Select(ab => new Button {
FontSize = Math.Max(16, titleSize),
Text = ab.Text,
FontAttributes = ab.IsPreferred ? FontAttributes.Bold : FontAttributes.None,
TextColor = ab.IsDestructive ? Color.Red : Color.Default,
Command = new Command(async () => {
var cont = true;
if (ab.Action != null)
cont = ab.Action();
if (ab.ActionAsync != null)
cont = cont && await ab.ActionAsync();
if (!cont)
await dismiss();
})
}).ToList();
var grid = new Grid {
RowDefinitions = {
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto }
},
ColumnSpacing = 0,
RowSpacing = 0
};
buttons.ForEach(button => {
grid.ColumnDefinitions.Add(
new ColumnDefinition {
Width = AlertWidth / buttonViews.Count
}
);
});
for (int i = 0; i < buttonViews.Count; i++)
{
grid.Children.Add(new BorderView {
BorderColor = Color.FromRgba(0,0,0,0.2),
Thickness = new Thickness(0, 1, (i + 1 < buttonViews.Count) ? 1 : 0, 0)
}, i, 1);
grid.Children.Add(buttonViews[i], i, 1);
}
grid.Children.Add(top, 0, buttons.Count, 0, 1);
var box = new Frame {
WidthRequest = AlertWidth,
BackgroundColor = Color.FromRgba(1,1,1,0.96),
Padding = 0,
Content = grid
};
var outer = new AbsoluteLayout {
BackgroundColor = Color.FromRgba(0,0,0,0.65),
Opacity = 0,
Children = { box }
};
AbsoluteLayout.SetLayoutFlags(box, AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(box,
new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
var page = new ContentPage {
Content = /* new ScrollView { Content = */ outer // }
};
var tcs = new TaskCompletionSource<object>();
var topVC = UIApplication.SharedApplication.KeyWindow.RootViewController;
while (topVC.PresentedViewController != null) {
topVC = topVC.PresentedViewController;
}
var vc = page.CreateViewController();
topVC.Add(vc.View);
var innerView = vc.View.Subviews[0].Subviews[0];
vc.View.RemoveFromSuperview();
dismiss = async () => {
dismiss = async () => {};
await outer.FadeTo(0, 50);
innerView.RemoveFromSuperview();
tcs.SetResult(null);
};
topVC.Add(innerView);
var kbh = new KeyboardHelper();
kbh.KeyboardChanged += async (sender, e) => {
await box.TranslateTo(0, e.Visible ? (-e.Height / 2f) : 0, 100, Easing.CubicInOut);
};
await outer.FadeTo(1, 100);
await tcs.Task;
}
This looks like an and/or problem between threading or simply not setting the task completion.
In the IOS version you have
dismiss = async () => {
dismiss = async () => {};
await outer.FadeTo(0, 50);
innerView.RemoveFromSuperview();
tcs.SetResult(null);
};
There is no matching tcs.SetResult(null); statement in the android version.
Also of note is the async invocation, as waiting to call SetResult will block the main thread without it.
I am new on this subject. What I try to do is train many SVM's for the same dataset with different parameters (different kind of signature of images in the future I hope) then predict each SVM and accept the mostly found class.
I tried to read many peoples' code about SVM image training, but couldn't figure out what I am doing wrong im my code. What ever I try, svm.Predict always return 0.
Any help or hint is very appreciated.
internal class SVMClassifier
{
Dictionary<int, string> classIndex_name;
List<SVM> svms;
internal void Train(string trainFolder)
{
this.classIndex_name = new Dictionary<int, string>();
Dictionary<int, List<Mat>> class_mats = getMats(trainFolder, this.classIndex_name);
this.svms = new List<SVM>();
Mat samples; Mat responses;
getTrainingData(class_mats, out samples, out responses);
svms.Add(trainSVM(samples, responses));
svms.Add(trainSVM(samples, responses, SVM.SvmType.CSvc, SVM.SvmKernelType.Linear, 0d, 0d, 10d, TermCritType.Iter | TermCritType.Eps, 1000, 0.000001d, 0d, 0d));
svms.Add(trainSVM(samples, responses, SVM.SvmType.CSvc, SVM.SvmKernelType.Rbf, 100d, 100d, 1d, TermCritType.Iter | TermCritType.Eps, 1000, 0.000001d, 0.1d, 0.5d));
samples.Dispose(); responses.Dispose();
foreach (Mat mat in class_mats.Values.SelectMany((a) => a))
mat.Dispose();
}
private static Dictionary<int, List<Mat>> getMats(string trainFolder, Dictionary<int, string> classIndex_name)
{
Dictionary<int, List<Mat>> class_mats = new Dictionary<int, List<Mat>>();
DirectoryInfo diTrain = new DirectoryInfo(trainFolder);
int i = 0;
foreach (var di in diTrain.GetDirectories())//classes are according to the directories
{
var dirName = di.Name;
classIndex_name[i] = dirName;
var fileNames = di.GetFiles().Select((a) => a.FullName).ToList();
fileNames.Sort(new Dece.Misc.NumericSuffixFileFullNameComparer());
class_mats[i] = fileNames.Select((a) => getMat(a, true)).ToList();
i++;
}
return class_mats;
}
private static SVM trainSVM(Mat samples, Mat responses,
SVM.SvmType? svm_Type = null, SVM.SvmKernelType? svm_KernelType = null, double? gamma = null, double? degree = null, double? c = null,
TermCritType? criteriaType = null, int? criteriaMaxCount = null, double? criteriaEps = null, double? p = null, double? nu=null)
{
SVM svm = new SVM();
if (svm_Type != null) svm.Type = (SVM.SvmType)svm_Type;
if (svm_KernelType != null) svm.SetKernel((SVM.SvmKernelType)svm_KernelType);
if (gamma != null) svm.Gamma = (double)gamma;
if (degree != null) svm.Degree = (double)degree;
if (c != null) svm.C = (double)c;
if ((criteriaType != null) || (criteriaMaxCount != null) || (criteriaEps != null))
{
var t = new MCvTermCriteria((int)criteriaMaxCount, (double)criteriaEps);
if (criteriaType != null) t.Type = (TermCritType)criteriaType;
svm.TermCriteria = t;
}
if (p != null) svm.P = (double)p;
if (nu != null) svm.Nu = (double)nu;
if (!svm.Train(samples, DataLayoutType.RowSample, responses))
throw new Exception();
return svm;
}
private static void getTrainingData(Dictionary<int, List<Mat>> class_mats, out Mat samples, out Mat responses)
{
samples = null;
List<int> lstResp = new List<int>();
foreach (int cls in class_mats.Keys)
{
int count = 0;
foreach (Mat mat in class_mats[cls])
using (var desc = mat.Reshape(0, 1))
{
if (samples == null)
samples = new Mat(desc.Cols, 0, desc.Depth, 1);
samples.PushBack(desc);
count += desc.Rows;
}
for (int i = 0; i < count; i++)
lstResp.Add(cls);
}
//responses = new Mat(new Size(lstResp.Count, 1), DepthType.Cv32S, 1);
//for (int i = 0; i < lstResp.Count; i++)
// responses.SetValue(0, i, lstResp[i]);
responses = new Mat(new Size(1, lstResp.Count), DepthType.Cv32S, 1);
for (int i = 0; i < lstResp.Count; i++)
responses.SetValue(i, 0, lstResp[i]);
if (samples.Depth != DepthType.Cv32F)
samples.ConvertTo(samples, DepthType.Cv32F);
CvInvoke.Normalize(samples, samples, -1, 1, NormType.MinMax);
}
internal void Detect(IEnumerable<string> fileNames, Action<ShapeInfo> detected)
{
foreach (var fn in fileNames)
using (Mat mat = getMat(fn, false))
{
{
using (var samples = mat.Reshape(0, 1))
{
if (samples.Depth != DepthType.Cv32F)
samples.ConvertTo(samples, DepthType.Cv32F);
CvInvoke.Normalize(samples, samples, -1, 1, NormType.MinMax);
foreach (var svm in this.svms)
{
Mat res = new Mat();
float p0 = svm.Predict(samples, res, 0);
float p1 = svm.Predict(samples, res, 1);
float p2 = svm.Predict(samples, res, 2);
float p3 = svm.Predict(samples, res, 3);
float p4 = svm.Predict(samples, res, 4);
float p = svm.Predict(samples, res);
foreach (var val in toIEnumerable(p0, p1, p2, p3, p4, p))
if (val != 0f)
{
System.Windows.Forms.MessageBox.Show("never enters here :(");
}
}
}
}
}
}
private static Mat getMat(string fn, bool train)
{
var mat = new Mat(fn, ImreadModes.Grayscale);
mat.Resize(new Size(128, 128));
return mat;
}
private static IEnumerable<T> toIEnumerable<T>(params T[] items)
{
if (items != null)
foreach (var item in items)
yield return item;
}
}
Mat.SetValue extension is taken from here.
I hope asking like that is propriate for this site's format. If not this question can be closed-erased, no problem. I am trying to understand how should we train an svm with images.
Yes I am stupid. The problem was sending an empty Mat to Predict function. When I tried null instead, I started to get the class predictions. (I still dont get why.)
Classification problem makes me feel like a dumb. Any comments about how I am using svm, what could-should be done is wellcome.
internal void Detect(IEnumerable<string> fileNames, Action<ShapeInfo> detected)
{
foreach (var fn in fileNames)
using (Mat mat = getMat(fn, false))
{
{
using (var samples = mat.Reshape(0, 1))
{
if (samples.Depth != DepthType.Cv32F)
samples.ConvertTo(samples, DepthType.Cv32F);
CvInvoke.Normalize(samples, samples, -1, 1, NormType.MinMax);
foreach (var svm in this.svms)
{
float p = svm.Predict(samples, null);
}
}
}
}
}
How could i delete annotations from the map after chosing the new one ?
So let's say i have chosen pin on the X and Y coordinates and would like to move this pin to another place without adding the new one.
Also simply map.RemoveAnnotations(); does not work.
Here is a code which depends on it:
map = new MKMapView(new CGRect(0, 74 + point * 13, UIScreen.MainScreen.Bounds.Width, (UIScreen.MainScreen.Bounds.Height - (74 + point * 20))));
map.UserInteractionEnabled = true;
map.ZoomEnabled = true;
map.ScrollEnabled = true;
map.MapType = MKMapType.Standard;
map.ShowsUserLocation = true;
var longTap = new UILongPressGestureRecognizer() { };
longTap.AddTarget(() => AddPin(longTap, slider.Value));
longTap.MinimumPressDuration = 2.0;
map.AddGestureRecognizer(longTap);
map.GetViewForAnnotation += (mapView, annotation) =>
{
anView = new MKAnnotationView(annotation, Resources.kClusterAnnotationId);
anView.ClipsToBounds = true;
anView.CanShowCallout = false;
anView.Image = UIImage.FromFile("Icons/customMapPin.png");
return anView;
};
private void AddPin(UILongPressGestureRecognizer longTap, float value)
{
if (ifPointExist == false)
{
ifPointExist = true;
touchPoint = longTap.LocationInView(map);
pinMapCords = this.map.ConvertPoint(touchPoint, map);
CLLocation loc = new CLLocation(pinMapCords.Latitude, pinMapCords.Longitude);
map.AddAnnotations(new MKPointAnnotation()
{
Coordinate = new CLLocationCoordinate2D(pinMapCords.Latitude, pinMapCords.Longitude)
});
CLGeocoder geocoder = new CLGeocoder();
geocoder.ReverseGeocodeLocation(loc, (CLPlacemark[] placemarks, NSError error) =>
{
str = placemarks[0].AddressDictionary;
str.ToString();
});
AddCircle(value);
MKCoordinateSpan span = new MKCoordinateSpan(0.10, 0.10);
var coords = new CLLocationCoordinate2D(pinMapCords.Latitude, pinMapCords.Longitude);
map.Region = new MKCoordinateRegion(coords, span);
ifPointExist = false;
}
}
Thanks in advance