i need to compare 2 photos similarity. For example picture of son and father and return a percentage of their similarity. I use for SkyBiometry.Client.FC. Something wrong with results returned by API. In all cases of recognizing i get 60%-68% of similarity(threshold).
Finally i tried to compare two same pictures and get result of 54%. I'm confused.What i do wrong? This is my code:
var client = new FCClient("my client id", "my client secret");
var path = Server.MapPath("~/Content/Upload/1");
var ids = new List<string> { "my client id" };
var urls = new List<string>();
Stream firstPicStream = System.IO.File.OpenRead(Path.Combine(path, "me.jpg"));
Stream secondPicStream = System.IO.File.OpenRead(Path.Combine(path, "me.jpg"));
var result1 = client.Faces.EndDetect(client.Faces.BeginDetect(null, new Stream[] { firstPicStream }, Detector.Aggressive, Attributes.Default, null, null));
var result2 = client.Faces.EndDetect(client.Faces.BeginDetect(null, new Stream[] { secondPicStream }, Detector.Aggressive, Attributes.Default, null, null));
urls.Add(result1.Photos[0].Url);
urls.Add(result2.Photos[0].Url);
var tags1 = result1.Photos[0].Tags;
var tags2 = result2.Photos[0].Tags;
var tagsIds = tags1.Select(tag => tag.TagId).ToList();
tagsIds.AddRange(tags2.Select(tag => tag.TagId));
var tagSaveResponce = client.Tags.EndSave(client.Tags.BeginSave(tagsIds, "My Namespace", "label", null, null));
var recognizeResult = client.Faces.EndRecognize(client.Faces.BeginRecognize(ids, urls, null, "My Namespace", Detector.Aggressive, Attributes.Default, null, null));
Did you call faces/train after tags/save for the user you save new tags for? Because if you don't you will perform recognition with old user tags only.
Also note that user id can not have spaces, make sure you check FCResponse.Status property for possible errors.
Related
I try to join two tables:
var data = from request in context.Requests
join account in context.AutolineAccts
on request.PkRequest.ToString() equals account.AccountCode
select new
{
ID = request.PkRequest.ToString(),
Location = request.FkLocation,
RequestDate = request.RequestDate.Value,
Requestor = request.FkRequestor,
DebitorNr = request.FkDebitor.ToString(),
NewDebit = request.Debit.ToString(),
ApprovalStatus = request.ApprovalStatus.ToString(),
RecommendationStatus = request.RecommendationStatus.ToString(),
DebitorName = account.CustomerSname,
Limit = account.CreditLimit
};
Now I want to filter the result set depending on the status of the user:
// Accounting user
if (ActiveDirectoryHelper.CheckIfUserIsInADGroup(userLogin, AdGroups.ACCOUNTING) )
req = data.Where(x => x.RecommendationStatus == null).ToList();
// After sales manager
else if (ActiveDirectoryHelper.CheckIfUserIsInADGroup(userLogin, AdGroups.SAV_LEADERS))
req = data.OrderByDescending(x => x.ID).ToList();
// Everybody else
else
req = data.OrderByDescending(x => x.PkRequest).ToList();
And that's where I'm stuck. When I don't have the join and only retrieve a "Request" type, I can just declare a list of Requests
List<Requests> req;
But with that combination of Requests and AutolineAccts I would have to declare and initialize a list of "items" (req) to assign the result set to in the if-else segments. But I don't know how that anonymous variable should look like.
Later on I have to map the result set to a list of my IndexViewModels:
foreach (var item in req)
viewModel.CLModels.Add(new IndexViewModel
{
ID = item .PkRequest.ToString(),
Location = item .FkLocation,
RequestDate = item .RequestDate.Value,
Requestor = item .FkRequestor,
DebitorNr = item .FkDebitor.ToString(),
NewDebit = item .Debit.ToString(),
ApprovalStatus = item .ApprovalStatus.ToString(),
RecommendationStatus = item .RecommendationStatus.ToString(),
DebitorName = item.CustomerSname,
Limit = item.CreditLimit
});
Any idea to solve this issue?
IEnumerable<dynamic> result = from request in requests
join account in accounts
on request.id equals account.id
select new {id=request.id, name=account.name};
Keeps the accessors, can further be queried and be return type of a method.
One option to avoid dynamic is to give the compiler an example of your anonymous type:
var req = new[]
{
new
{
ID = "",
Location = "",
RequestDate = DateTime.Now,
Requestor = "",
DebitorNr = "",
NewDebit = "",
ApprovalStatus = "",
RecommendationStatus = "",
DebitorName = "",
Limit = 0
}
}.ToList();
Obviously you should adjust the values to match the type that you expect.
It's a bit ugly, but personally I'd prefer that over using dynamic typing.
If you wanted to avoid actually allocating the array and the list, you could use type inference in a fairly horrible way:
// Simple method that returns null, but enables type inference
public static List<T> ProvideNullList(T sample) => null;
// Call it when you want to declare your variable:
var sample = new
{
ID = "",
Location = "",
RequestDate = DateTime.Now,
Requestor = "",
DebitorNr = "",
NewDebit = "",
ApprovalStatus = "",
RecommendationStatus = "",
DebitorName = "",
Limit = 0
};
var req = GenericHelpers.ProvideNullList(sample);
That does still allocate the sample, but it's at least a bit better than the array and list as well.
In the following documentation, it states that you can
...provide arbitrary key/value pairs beyond the reserved names and those will be stored with the user
In C# code, I have the following:
var _user = new {
Login = "fred",
EmailAddress = "fred#here.com",
Name = "Fred Flintstone"
}
SentrySdk.ConfigureScope( scope => {
scope.User = new Sentry.Protocol.User()
{
Id = _user.Login,
Email = _user.EmailAddress,
Username = _user.Login
};
});
Is there a way to add Name (or any other field)? Or is the documentation just referring to tags?
You can add your custom user data via the Other property.
The latest version of the Sentry.Protocol has Other as a IReadOnlyDictionary which means you need to assign a new instance like:
var sut = new User
{
Id = "user-id",
Email = "test#sentry.io",
IpAddress = "::1",
Username = "user-name",
Other = new Dictionary<string, string>
{
{"Name", "your name"},
{"anything else", "whatever"},
}
};
This PR is making Other mutable so you can add data like:
var user = new User();
user.Other.Add("key", "value");
I have the following code that supposedly gets the users "email". "fistname", "lastname", "id" and "gender":
var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me?fields=first_name,last_name,gender,email"), null, eventArgs.Account);
var response = await request.GetResponseAsync();
var obj = JObject.Parse(response.GetResponseText());
var id = obj["id"].ToString().Replace("\"", "");
var firstname = obj["first_name"].ToString().Replace("\"", "");
var lastName = obj["last_name"].ToString().Replace("\"", "");
var gender = obj["gender"].ToString().Replace("\"", "");
var email = obj["email"].ToString().Replace("\"", "");
I am able to get every thing properly except the email field, which is null. Am i treating the string wrongly, or is my Uri incorrect to begin with ?
I've got a database containing several collections. Some has got a name like "carpenter_title_year_version". Others has got a name like "plumber_title_year_version". How do I set up a filter to retrieve all collections where the string "carpenter" is in the collectionname?
I'm thinking something like:
var filterBuilder = Builders<GroupEntity>.Filter;
var projectionBuilder = Builders<GroupEntity>.Projection;
var collection = Database.GetCollection<GroupEntity>("dbname");
var filter = filterBuilder.ElemMatch("carpenter..., ?"); //<--- ???
var projection = projectionBuilder.Exclude("_id");
var list = await collection.Find(filter).Project(projection).ToListAsync();
There's (and an async version of it)
IAsyncCursor<MongoDB.Bson.BsonDocument> IMongoDatabase.ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = null);
You can use the filter from the collection options to match the collection name.
// <CAPS INSIDE> are wildcards
var _client = new MongoClient(#"connection string");
var _database = _client.GetDatabase("<DATABASE NAME>");
var bre = new BsonRegularExpression("<YOUR REGEX PATTERN>");
var copt = new ListCollectionsOptions{ Filter =
Builders<BsonDocument>.Filter.Regex ("name", bre )
};
var collectionsWithMatchingNames = _database.ListCollections(copt).ToList().Select (col => col["name"]);
Only then you get your particular collection, like:
foreach (var x in collectionsWithMatchingNames)
var collection = _database.GetCollection<BsonDocument>(x);
Currently I’m having some difficulties with using new Magento's soap v2 from c# interface.
With php i was able to do something like this:
$params["created_at"]["from"] = date("Y-m-d H:i:s",Functions::convert_time($dataDa));
$params["created_at"]["to"] = date("Y-m-d H:i:s",Functions::convert_time($dataA));
MageInterface::getSingleton()->shipmentList($params);
In this mode i was able to find list of orders which were created from $dataDa to $dataA without problems. With c# however it seems that only the last one of the selectors work.
My code:
var cpf = new complexFilter[2];
cpf[0] = new complexFilter
{
key = "created_at",
value = new associativeEntity
{
key = "to",
value = uxDataA.DateTime.ToString("yy-MM-dd HH:mm:ss")
}
});
cpf[1] = new complexFilter
{
key = "created_at",
value = new associativeEntity
{
key = "from",
value = uxDataDa.DateTime.ToString("yy-MM-dd HH:mm:ss")
}
});
var filters = new filters();
filters.complex_filter = cpf;
var risultato = mage.salesOrderList(sessionKey, filters);
In this mode only created_at->from criteria is taken in consideration (it's like second complex filter override previous one with the same key). Ideas?
Thanks in advance.
This works for me :
private filters addFilter(filters filtresIn, string key, string op, string value)
{
filters filtres = filtresIn;
if (filtres == null)
filtres = new filters();
complexFilter compfiltres = new complexFilter();
compfiltres.key = key;
associativeEntity ass = new associativeEntity();
ass.key = op;
ass.value = value;
compfiltres.value = ass;
List<complexFilter> tmpLst;
if (filtres.complex_filter!=null)
tmpLst = filtres.complex_filter.ToList();
else tmpLst = new List<complexFilter>();
tmpLst.Add(compfiltres);
filtres.complex_filter = tmpLst.ToArray();
return filtres;
}
and call
{
Mage_Api_Model_Server_V2_HandlerPortTypeClient clientSoap = new Mage_Api_Model_Server_V2_HandlerPortTypeClient();
string sessionId = clientSoap.login(LOG, PASS);
filters filtres = new filters();
filtres = addFilter(filtres, "status", "eq", "processing");
filtres = addFilter(filtres, "created_at", "from", "2014-09-07 08:00:00");
filtres = addFilter(filtres, "created_at", "to", "2014-09-07 00:00:00");
salesOrderEntity[] lst = clientSoap.salesOrderList(sessionId, filtres);
}
Solved, there was a bug (or the feature?) in mage\sales\order\api\v2.php
See more info in this thread: http://www.magentocommerce.com/boards/viewthread/70368/