AForge Hough Transform - geometry

Im trying to do an experiment on how to use the HoughTransformation class of AForge. Im using this class to try to count the number of circles on an image. But I always got this error message: Unsupported pixel format of the source image.
Here is my code:
private void CountCircles(Bitmap sourceImage)
{
HoughCircleTransformation circleTransform = new HoughCircleTransformation(15);
circleTransform.ProcessImage(sourceImage);
Bitmap houghCircleImage = circleTransform.ToBitmap();
int numCircles = circleTransform.CirclesCount;
MessageBox.Show("Number of circles found : "+numCircles.ToString());
}

HoughCircleTransformation expects a binary bitmap.
private void CountCircles(Bitmap sourceImage)
{
var filter = new FiltersSequence(new IFilter[]
{
Grayscale.CommonAlgorithms.BT709,
new Threshold(0x40)
});
var binaryImage = filter.Apply(bitmap);
HoughCircleTransformation circleTransform = new HoughCircleTransformation(15);
circleTransform.ProcessImage(binaryImage);
Bitmap houghCircleImage = circleTransform.ToBitmap();
int numCircles = circleTransform.CirclesCount;
MessageBox.Show("Number of circles found : "+numCircles.ToString());
}

Related

Can't convert string to ui text in unity

I have looked around for solutions but nothing has worked so far, here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BirdController : MonoBehaviour
{
public float jumpVelocity;
public Text jumpCooldownDisplayText = "";
public float speed = 18;
private Rigidbody rb;
public float jumpCooldown = 0f;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate ()
{
jumpCooldown -= Time.deltaTime;
jumpCooldownDisplayText = Mathf.Round (jumpCooldown).ToString();
if (Input.GetButtonDown ("Jump") && jumpCooldown <= 0)
{
rb.velocity = Vector3.up * jumpVelocity;
jumpCooldown = 0.5f;
}
float hAxis = Input.GetAxis("Horizontal");
float vAxis = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(hAxis*speed, 0, vAxis*speed) * Time.deltaTime;
rb.MovePosition(transform.position + movement);
}
}
The error I'm getting is "Cannot implicitly convert type string' toUnityEngine.UI.Text'". I'm getting this error into different places of the code.
UI.Text is a UI text component, not the associated string. What you want is the text property of the UI Text:
jumpCooldownDisplayText.text = Mathf.Round (jumpCooldown).ToString();

How to unite gameobject meshes?

Because of I made my house from the unity editor I can't remove this mesh borders. I tried MeshCombiner but it just connects all of the meshes in one mesh borders still exist. I know I can make it from Blender or something like this but is there any one to remove from unity?
Screen Shot: http://imgur.com/a/1XALE
Maybe you are looking for CombineMeshes. An example is
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class ExampleClass : MonoBehaviour {
void Start() {
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length) {
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.active = false;
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
transform.gameObject.active = true;
}
}

Draw states in mapControl

I'm writing an application for windows Phone and I'm using a MapControl.
I'd like to be able to paint the US States in different colors.
For example, CA in Red, NV in blue, etc
I Thought about doing Shapes and Polilines, but I can't find the coordinates to use in the shapes to get the different States.
I also tried using the
var found = await MapLocationFinder.FindLocationsAsync("California", new Geopoint(new BasicGeoposition()));
but it doesn't work for finding States.
The best way is to download GeoJSON files from this public repository
https://github.com/johan/world.geo.json/tree/master/countries/USA
Parse the JSON and Create MapPolygon object and add it to map.
public async void RenderState() {
HttpClient client = new HttpClient();
HttpResponseMessage response=await client.GetAsync(new Uri("https://raw.githubusercontent.com/johan/world.geo.json/master/countries/USA/CO.geo.json"));
string json=response.Content.ToString();
JObject obj = JObject.Parse(json);
JObject poly = (JObject)obj["features"][0]["geometry"];
JArray coords = (JArray)poly["coordinates"][0];
MapPolygon polygon = new MapPolygon();
List<BasicGeoposition> points = new List<BasicGeoposition>();
foreach (JArray arr in coords) {
points.Add(new BasicGeoposition() { Latitude = (double)arr[1], Longitude = (double)arr[0] });
}
//Remove last point as it is a duplicate
if (points.Count > 1) {
points.RemoveAt(points.Count - 1);
}
polygon.Path = new Geopath(points);
polygon.StrokeColor = Colors.Red;
polygon.FillColor = Colors.Blue;
this.mMap.MapElements.Add(polygon);
}
This code will render the state of colarado

Read a PNG image using Haxe

Using the Haxe programming language, is there any cross-platform way to read a PNG image, and get the pixel data from the image?
I have a file called stuff.png, and I want to obtain an array of RGB values from the image (as an integer array).
Here's an example usage of the Haxe format library to read a PNG file. You need -lib format in your compiler args / build.hxml:
function readPixels(file:String):{data:Bytes, width:Int, height:Int} {
var handle = sys.io.File.read(file, true);
var d = new format.png.Reader(handle).read();
var hdr = format.png.Tools.getHeader(d);
var ret = {
data:format.png.Tools.extract32(d),
width:hdr.width,
height:hdr.height
};
handle.close();
return ret;
}
Here's an example of how to get ARGB pixel data from the above:
public static function main() {
if (Sys.args().length == 0) {
trace('usage: PNGReader <filename>');
Sys.exit(1);
}
var filename = Sys.args()[0];
var pixels = readPixels(filename);
for (y in 0...pixels.height) {
for (x in 0...pixels.width) {
var p = pixels.data.getInt32(4*(x+y*pixels.width));
// ARGB, each 0-255
var a:Int = p>>>24;
var r:Int = (p>>>16)&0xff;
var g:Int = (p>>>8)&0xff;
var b:Int = (p)&0xff;
// Or, AARRGGBB in hex:
var hex:String = StringTools.hex(p,8);
trace('${ x },${ y }: ${ a },${ r },${ g },${ b } - ${ StringTools.hex(p,8) }');
}
}
You can always access the pixel data with BitmapData.getPixels/BitmapData.setPixels.
If you are using haXe NME, you can use Assets.getBitmapData() to load an asset image file.
If you want to load images from network, then you can use Loader class, it can asynchronous loading remote images, but in flash please mind the cross-domain issue.
For more generic ByteArray -> BitmapData conversion, use following code:
var ldr = new Loader();
ldr.loadBytes(cast(byteArray)); // bytearray contains raw image data
var dp: DisplayObject = ldr.content; // actually ontent should be of Bitmap class
var bitmapData = new BitmapData(Std.int(dp.width), Std.int(dp.height), true, 0);
bitmapData.draw(dp);

How do i use the Emgu CV _SmoothGausian Method

Im trying to get the OCR sample app to recognise some small text and how I'm doing it is to resize the image. Once I have resized the image it is all 'pixel-ee'
I want to use the SmothGaussian method to clean it up but I get an error each time I execute the method
Here is the code:
Image<Bgr, Byte> image = new Image<Bgr, byte>(openImageFileDialog.FileName);
using (Image<Gray, byte> gray = image.Convert<Gray, Byte>().Resize(800, 600, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR, true))
{
gray.Convert<Gray, Byte>()._SmoothGaussian(4);
_ocr.Recognize(gray);
Tesseract.Charactor[] charactors = _ocr.GetCharactors();
foreach (Tesseract.Charactor c in charactors)
{
image.Draw(c.Region, drawColor, 1);
}
imageBox1.Image = image;
//String text = String.Concat( Array.ConvertAll(charactors, delegate(Tesseract.Charactor t) { return t.Text; }) );
String text = _ocr.GetText();
ocrTextBox.Text = text;
}
Here is the image:
_SmoothGaussian can only handle odd numbers as kernel size so try with 3 or 5 as argument instead.

Resources