Is it possible to detect Gender using Google.Cloud.Vision - c#

I found some code examples of detecting face:
var image = Image.FromFile(filePath);
var client = ImageAnnotatorClient.Create();
var response = client.DetectFaces(image);
int count = 1;
foreach (var faceAnnotation in response)
{
Console.WriteLine("Face {0}:", count++);
Console.WriteLine(" Joy: {0}", faceAnnotation.JoyLikelihood);
Console.WriteLine(" Anger: {0}", faceAnnotation.AngerLikelihood);
Console.WriteLine(" Sorrow: {0}", faceAnnotation.SorrowLikelihood);
Console.WriteLine(" Surprise: {0}", faceAnnotation.SurpriseLikelihood);
}
But I couldn't find 'IsMale' or 'Gender' property in faceAnnotation. How can I detect Gender using Google.Cloud.Vision?

I think AWS Rekognition could provide gender:
Q: What face attributes can I get from Amazon Rekognition?
Amazon Rekognition returns the following facial attributes for each face detected, along with a bounding box and confidence score for each attribute:
Gender
Smile
...
see: https://aws.amazon.com/rekognition/faqs/

Related

Enumerate audio input devices with WMI

I am using NAudio in my C# project, and I am looking for a way to enumerate audio input devices (microphone etc.), so i can get full name of them (not only the 31-characters long name that i can get from NAudio). I went through a few posts where people were enumerating audio output devices with WMI:
ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(
"SELECT * FROM Win32_SoundDevice");
ManagementObjectCollection objCollection = objSearcher.Get();
Is it possible to enumerate input devices this way as well?
Thanks
To explore the WMI queries you can use a tool that generates the WMI code for you. You'll have plenty of WMI management classes to get the information from.
You can download the tool from Microsoft download center here
I wrote a blog post few years back about using WMI management services for administration. Hope this would give you a head start.
Here's snippet generated from the tool to get the list of installed sound cards on the device.
public static void Main()
{
try
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_SoundDevice");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("List of sound cards installed");
Console.WriteLine("-----------------------------------");
Console.WriteLine("ProductName: {0}", queryObj["ProductName"]);
Console.WriteLine("Availability: {0}", queryObj["Availability"]);
Console.WriteLine("Caption: {0}", queryObj["Caption"]);
Console.WriteLine("ConfigManagerErrorCode: {0}", queryObj["ConfigManagerErrorCode"]);
Console.WriteLine("ConfigManagerUserConfig: {0}", queryObj["ConfigManagerUserConfig"]);
Console.WriteLine("CreationClassName: {0}", queryObj["CreationClassName"]);
Console.WriteLine("Description: {0}", queryObj["Description"]);
Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
Console.WriteLine("DMABufferSize: {0}", queryObj["DMABufferSize"]);
Console.WriteLine("ErrorCleared: {0}", queryObj["ErrorCleared"]);
Console.WriteLine("ErrorDescription: {0}", queryObj["ErrorDescription"]);
Console.WriteLine("InstallDate: {0}", queryObj["InstallDate"]);
Console.WriteLine("LastErrorCode: {0}", queryObj["LastErrorCode"]);
Console.WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
Console.WriteLine("MPU401Address: {0}", queryObj["MPU401Address"]);
Console.WriteLine("Name: {0}", queryObj["Name"]);
Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
Console.WriteLine("PowerManagementSupported: {0}", queryObj["PowerManagementSupported"]);
Console.WriteLine("Status: {0}", queryObj["Status"]);
Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);
Console.WriteLine("SystemCreationClassName: {0}", queryObj["SystemCreationClassName"]);
Console.WriteLine("SystemName: {0}", queryObj["SystemName"]);
}
}
catch (ManagementException e)
{
Console.WriteLine("An error occurred while querying for WMI data: " + e.Message);
}
}
Here's the output -
-----------------------------------
List of sound cards installed
-----------------------------------
ProductName: Realtek High Definition Audio
Availability:
Caption: Realtek High Definition Audio
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_SoundDevice
Description: Realtek High Definition Audio
DeviceID: HDAUDIO\FUNC_01&VEN_10EC&DEV_0662&SUBSYS_103C304A&REV_1001\4&3867FD9A&0&0001
DMABufferSize:
ErrorCleared:
ErrorDescription:
InstallDate:
LastErrorCode:
Manufacturer: Realtek
MPU401Address:
Name: Realtek High Definition Audio
PNPDeviceID: HDAUDIO\FUNC_01&VEN_10EC&DEV_0662&SUBSYS_103C304A&REV_1001\4&3867FD9A&0&0001
PowerManagementSupported: False
Status: OK
StatusInfo: 3
SystemCreationClassName: Win32_ComputerSystem
SystemName: PC-2322Q1
These are sound devices, so it includes input and output devices. Soundcards can have 0 or more outputs and 0 or more inputs.

.Contains() on file contents not working as expected

I am trying to create an ai. I have got it to write a topic with information to a text file but cant get it to read. this is what i have so far. Any ideas on why it isnt working?
string information = "blank";
Console.WriteLine("Hello my name is Lou-C.");
Console.WriteLine("What is yours?");
string name = Console.ReadLine();
Console.WriteLine("Hello {0}, What do you want to talk about?", name);
string topic = Console.ReadLine();
string[] lines = System.IO.File.ReadAllLines(#"C:\Users\simon.light\Documents\Visual Studio 2013\Projects\Lou-c\Lou-c\information.txt");
if (lines.Contains("beat"))
{
Console.WriteLine("Aaahh, {0}, I have heard of this before");
Console.WriteLine("Tell me what you know about this");
information = Console.ReadLine();
}
else
{
Console.WriteLine("{0}? I don't think i have come across this before.", topic);
Console.WriteLine("Tell me about it");
information = Console.ReadLine();
}
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(#"C:\Users\simon.light\Documents\Visual Studio 2013\Projects\Lou-c\Lou-c\information.txt", true))
{
file.WriteLine("${0} - %{1} - by {2}", topic, information, name);
}
To check for any line that contains "beat"
if (lines.Any(s => s.Contains("beat")))
However, if you used ReadAllText then your contains would work!
string text = System.IO.File.ReadAllText(...);
if (text.Contains("beat"))

C# - Hardware status check, working but crashing

Working but crashing is weird to say, but the hardware status gets printed in the console window but my application crash when i run this. I have it on the load of the form.
Error says: Object reference not set to an instance of an object
And here is the code:
// Hardware check
ManagementObjectSearcher deviceList =
new ManagementObjectSearcher("Select Name, Status from Win32_PnPEntity");
// Any results? There should be!
if (deviceList != null)
// Enumerate the devices
foreach (ManagementObject device in deviceList.Get())
{
// To make the example more simple,
string name = device.GetPropertyValue("Name").ToString();
string status = device.GetPropertyValue("Status").ToString();
// Uncomment these lines and use the "select * query" if you
// want a VERY verbose list
// foreach (PropertyData prop in device.Properties)
// Console.WriteLine( "\t" + prop.Name + ": " + prop.Value);
// More details on the valid properties:
//
Console.WriteLine("Device name: {0}", name);
Console.WriteLine("\tStatus: {0}", status);
// Part II, Evaluate the device status.
bool working = ((status == "OK") || (status == "Degraded")
|| (status == "Pred Fail"));
Console.WriteLine("\tWorking?: {0}", working);
}
So your problem when working with management objects is that all properties can return null and you need to account for this at all times as well as some other issues:
The searcher is not a list of devices nor will it ever contain one so you shouldn't call it deviceList.
You don't need to check the searcher for a value as all we're doing is initializing the class, it won't fail without an Exception.
You need to clean up after yourself by disposing of the management objects.
Since both Name and Status properties are strings anyway, you can cast them as such without calling .ToString() and use ?? string.Empty to replace null values with an empty string.
// Hardware check
using (ManagementObjectSearcher deviceSearcher = new ManagementObjectSearcher("Select Name, Status from Win32_PnPEntity"))
using (ManagementObjectCollection devices = deviceSearcher.Get())
{
// Enumerate the devices
foreach (ManagementObject device in devices)
{
// To make the example more simple,
string name = (string)device.GetPropertyValue("Name") ?? string.Empty;
string status = (string)device.GetPropertyValue("Status") ?? string.Empty;
// Uncomment these lines and use the "select * query" if you
// want a VERY verbose list
// foreach (PropertyData prop in device.Properties)
// Console.WriteLine("\t{0}: {1}", prop.Name, prop.Value);
// More details on the valid properties:
//
Console.WriteLine("Device name: {0}", name);
Console.WriteLine("\tStatus: {0}", status);
// Part II, Evaluate the device status.
bool working = status == "OK" || status == "Degraded" || status == "Pred Fail";
Console.WriteLine("\tWorking?: {0}", working);
}
}

Calling My REST API Using C#

I'm trying to call my own REST API that returns JSON using a simple C# GUI application, and am looking for the simplest way to do so:
http://danielmiessler.com:44821/token/dGVxdWllcm8=
I am opening a file containing tokens and reading the contents line by line to get the final part of the URL:
StreamReader input = new StreamReader(openFileDialog1.OpenFile());
while ((line = input.ReadLine()) != null) {
This is going back into a textbox:
textBox2.Text += ("\t" + result + "\r\n");
Here is the Ruby code I'm trying to reproduce:
# Get our libraries
require 'httparty'
require 'json'
# Get our input from the command line
input = ARGV[0]
# Loop through the file
File.open("#{input}", "r").each_line do |line|
# Request the URL
response = HTTParty.get("http://danielmiessler.com:44821/token/#{line.chomp}")
# Go through the responses
case response.code
when 400
print "Improper input…\n"
# Feel free to remove this line if you want to reduce output.
when 200
json = JSON.parse(response.body)
print "Your input is #{json['type']} of the word: #{json['value']}\n"
when 404
print "There is no meaning in your token…\n"
# Feel free to remove this line if you want to reduce output.
end
end
Any ideas how to make the calls based on the tokens in the file and output to the text box?
You can use HttpClient for that.
This is a minimal example to get you started:
static void Main(string[] args)
{
HttpClient client = new HttpClient();
client.GetAsync(_address).ContinueWith(
(requestTask) =>
{
HttpResponseMessage response = requestTask.Result;
response.EnsureSuccessStatusCode();
response.Content.ReadAsAsync<JsonArray>().ContinueWith(
(readTask) =>
{
Console.WriteLine(
"First 50 countries listed by The World Bank...");
foreach (var country in readTask.Result[1])
{
Console.WriteLine(" {0}, Country Code: {1}, " +
"Capital: {2}, Latitude: {3}, Longitude: {4}",
country.Value["name"],
country.Value["iso2Code"],
country.Value["capitalCity"],
country.Value["latitude"],
country.Value["longitude"]);
}
});
});
Console.WriteLine("Hit ENTER to exit...");
Console.ReadLine();
}

Getting USB drive name attached to windows ce device

How to get name of usb drive attahced to my Windows ce device using c# or any or the native API.
You may be able to start with the C# DriveInfo class:
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 15} bytes",
d.AvailableFreeSpace);
Console.WriteLine(
" Total available space: {0, 15} bytes",
d.TotalFreeSpace);
Console.WriteLine(
" Total size of drive: {0, 15} bytes ",
d.TotalSize);
}
}
http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
or this may help:
Get List of connected USB Devices
The folder name is localized and can change from device to device. The way I do it is to query it from the same registry location the driver used for getting the name:
using(var key = Registry.LocalMachine.OpenSubKey(
#"\System\StorageManager\Profiles\USBHDProfile"))
{
USBDiskFolderName = key.GetValue("Folder").ToString();
}

Categories

Resources