|
Well without some frame of reference you can't.
|
|
|
|
|
If you don't have to details on the lens being used by the camera, it's impossible to calculate. You also need to calibrate the system with known points in the image. How accurate you get is also dependent on the object you're measuring distance to. You're not going to get an accurate distance to the center of a ball in the image.
Also, the accuracy is going to be rather poor if you're only using one camera and nothing else.
System.ItDidntWorkException: Something didn't work as expected.
C# - How to debug code[ ^].
Seriously, go read these articles.
Dave Kreskowiak
|
|
|
|
|
Place reference objects / lines in the "frame".
Wonder why there is a "ruler" on the side of doors leading in / out of banks?
Or the "lines on the road" used to measure speed / distance over time (from above).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
my projects link button not work in iphone 6s but desktop work properly why?
|
|
|
|
|
???? What? Sorry, but what has this got to do with C#? Is it code related? If so, what code do you have? Remember that we can't see your screen, so you have to give us a lot more detail than this if you want us to be able to help you.
This space for rent
|
|
|
|
|
Because there's a secret bug in your secret code.
Seriously, how do you expect anybody to be able to help you based on the complete lack of information you've provided?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You may be surprised to know that an iPhone 6 and a Desktop are actually different devices.
|
|
|
|
|
Maybe it's a "Windows-only" link.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hello,
I would like to validate strings to datetime format using regex please
modified 15-Nov-17 6:00am.
|
|
|
|
|
Not with regular expressions!
Use DateTime.TryParseExact[^] to validate the string against your required format.
However, there's a small problem. Your "valid" string doesn't actually match the format you're validating against. Your format requires the letter "T" between the date and time, but neither of your strings have that.
string input = "2017-09-19T08:04:31.123";
DateTime parsedDate;
bool isValid = DateTime.TryParseExact(input,
"yyyy-MM-ddThh:mm:ss.fff",
CultureInfo.InvariantCulture,
DateTimeStyles.AssumeUniversal,
out parsedDate);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
DateTime dt = DateTime.ParseExact(input, "yyyy-MM-dd hh:mm:ss.fff", CultureInfo.InvariantCulture);
|
|
|
|
|
In practice, you would wrap a call to DateTime.ParseExact in a try/catch block ... because it will throw an error if it fails.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
Better to use TryParseExact , which won't.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am actively looking for the best library that will allow assessing the multiple values, based on weights (preferable as int instead of double from 10,000 - 120,000).
I was looking into many different examples but each one of them is either operating on linear functions or using double.
Let say I will have 4 columns:
Column A, Column B, Column C, Column D
120, 3, 3.23, false
84, 12, 2.12, false,
22, 3, 2.1, true
Which AI C# library could assess the output based on weights (column A weight from (10k to 120k depending on the int))
I am kinda stuck here. Looking for a way to start with this, even with simpler example (so just with two columns like column 120 = 10k, 84 = 11k, 22 = 23k, column b = 0.3, 1.2, 0.3)).
I will greatly appreciate any direction just to get me started
Thanks in advance.
|
|
|
|
|
A neural network can be used to perform a "non-linear" regression.
Test Run - Neural Network Regression
(As for the "best" library... never heard of one).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you for a link!
I was sure that it is possible, as I was using different samples and one of them can even generate simple working code with an output.
I just need to get well explained example to start from that point
THANK YOU VERY MUCH !
|
|
|
|
|
You're welcome!
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Unfortunately, it doesn't seem practical to link anything less than my whole program to solve this issue: Solver[^] If I'm wrong about that, I'd be happy to hear how in addition to the answer to the question itself so I can ask more manageable questions in the future.
The bug occurs for the text input "32^(1/5)", without quotes, somewhere during the fourth execution for the foreach loop on line 635. The four pairs of lines that print when the program is executed with this input are the WriteLine() calls on lines 639 and 642. I added those calls in the hope of seeing how the collection in question differs before and after line 640 executes, but evidently, whatever the alteration is is not revealed by the ToString() override of its element. I don't know what kind of alteration this could be.
The multiply() override called by the * in line 640 at this point - the one on line 611 in the Product class - does touch the contents of Factors, but only once, on line 617:
List<Factor> factors = new List<Factor>(Factors);
I thought that this makes factors a copy of Factors rather than another reference to the same object, so that making changes to the former doesn't affect the latter.
|
|
|
|
|
It makes a copy of Factors yes - in that it copies the reference to each object in the collection to a new collection, it does not duplicate the items themselves (a shallow copy, rather than a deep copy).
The new collection refers to exactly the same objects as the old one, and any change to those objects will be visible from both collections:
public class MyClass
{
public int X;
}
private void MyButton_Click(object sender, EventArgs e)
{
List<MyClass> items = new List<MyClass>() { new MyClass(){X = 111}, new MyClass(){X = 222}, new MyClass(){X = 333} };
List<MyClass> itemsCopy = new List<MyClass>(items);
items[0].X = 666;
itemsCopy[1].X = 777;
foreach (MyClass m in items)
{
Console.WriteLine(m.X);
}
...
Will generate:
666
777
333 So if you will have to look closely at what you are doing with your new collection and the objects it contains.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I intended to make all of my Number classes immutable, and thought I had done so. If they are in fact immutable, is there any danger left?
|
|
|
|
|
Depends on how immutable you made them!
You know how to do that, I assume:
1) Remove the setters of the class, only have getters.
2) Provide all parameters via constructor.
3) Make all variables readonly .
Do note that doesn't mean that any collections an immutable class contains will themselves be immutable: Add and Remove will still work for example, only the assignment of a new collection will not be possible.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OK, so I'm creating a simple card game. So far I can move my cards with mouse and this work as it should, but on the other hand I feel that most of my code is wrong because I had to repeat the same method for each object. So I'd like to simplify my code. Tried to use lists, collections and 'foreach' loops, but couldn't make it work. How can I make my code smaller, simpler and more elegant?
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class MainForm : Form {
class Card {
public int Type;
public Rectangle Position;
public Bitmap Image;
public Card(int Type, Rectangle Position) {
this.Type = Type;
switch (Type) {
case 1:
Image = new Bitmap("1.png");
break;
case 2:
Image = new Bitmap("2.png");
break;
case 3:
Image = new Bitmap("3.png");
break;
case 4:
Image = new Bitmap("4.png");
break; }
this.Position = Position; } }
Card RedCard = new Card(1, new Rectangle(0, 32, 32, 32));
Card BlueCard = new Card(2, new Rectangle(0, 64, 32, 32));
Card GreenCard = new Card(3, new Rectangle(0, 96, 32, 32));
Card YellowCard = new Card(4, new Rectangle(0, 128, 32, 32));
Card RedCard2 = new Card(1, new Rectangle(0, 160, 32, 32));
int IsTaken = 0, OffsetX = 0, OffsetY = 0;
PictureBox Table = new PictureBox();
void DrawTable(object sender, PaintEventArgs e) {
Color FirstColor = Color.FromArgb(46, 135, 46);
e.Graphics.FillRectangle(new SolidBrush(FirstColor), 0, 0, 400, 400); }
void DrawCards(object sender, System.Windows.Forms.PaintEventArgs e) {
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.DrawImage(RedCard.Image, RedCard.Position);
e.Graphics.DrawImage(BlueCard.Image, BlueCard.Position);
e.Graphics.DrawImage(GreenCard.Image, GreenCard.Position);
e.Graphics.DrawImage(YellowCard.Image, YellowCard.Position);
e.Graphics.DrawImage(RedCard2.Image, RedCard2.Position); }
int IsCursorOverCard(int X, int Y) {
if ((X > RedCard.Position.Left) && (X <= RedCard.Position.Right) && (Y > RedCard.Position.Top) && (Y <= RedCard.Position.Bottom))
return 1;
else if ((X > BlueCard.Position.Left) && (X <= BlueCard.Position.Right) && (Y > BlueCard.Position.Top) && (Y <= BlueCard.Position.Bottom))
return 2;
else if ((X > GreenCard.Position.Left) && (X <= GreenCard.Position.Right) && (Y > GreenCard.Position.Top) && (Y <= GreenCard.Position.Bottom))
return 3;
else if ((X > YellowCard.Position.Left) && (X <= YellowCard.Position.Right) && (Y > YellowCard.Position.Top) && (Y <= YellowCard.Position.Bottom))
return 4;
else if ((X > RedCard2.Position.Left) && (X <= RedCard2.Position.Right) && (Y > RedCard2.Position.Top) && (Y <= RedCard2.Position.Bottom))
return 5;
else
return 0; }
void RedrawRedCard(object sender, System.Windows.Forms.PaintEventArgs e) {
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.DrawImage(RedCard.Image, RedCard.Position); }
void RedrawBlueCard(object sender, System.Windows.Forms.PaintEventArgs e) {
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.DrawImage(BlueCard.Image, BlueCard.Position); }
void RedrawGreenCard(object sender, System.Windows.Forms.PaintEventArgs e) {
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.DrawImage(GreenCard.Image, GreenCard.Position); }
void RedrawYellowCard(object sender, System.Windows.Forms.PaintEventArgs e) {
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.DrawImage(YellowCard.Image, YellowCard.Position); }
void RedrawRedCard2(object sender, System.Windows.Forms.PaintEventArgs e) {
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
e.Graphics.DrawImage(RedCard2.Image, RedCard2.Position); }
void TakeCard(object sender, MouseEventArgs e) {
switch (IsCursorOverCard(e.X, e.Y)) {
case 1:
this.Table.Paint += new PaintEventHandler(this.RedrawRedCard);
IsTaken = 1;
OffsetX = RedCard.Position.X - e.X;
OffsetY = RedCard.Position.Y - e.Y;
break;
case 2:
this.Table.Paint += new PaintEventHandler(this.RedrawBlueCard);
IsTaken = 2;
OffsetX = BlueCard.Position.X - e.X;
OffsetY = BlueCard.Position.Y - e.Y;
break;
case 3:
this.Table.Paint += new PaintEventHandler(this.RedrawGreenCard);
IsTaken = 3;
OffsetX = GreenCard.Position.X - e.X;
OffsetY = GreenCard.Position.Y - e.Y;
break;
case 4:
this.Table.Paint += new PaintEventHandler(this.RedrawYellowCard);
IsTaken = 4;
OffsetX = YellowCard.Position.X - e.X;
OffsetY = YellowCard.Position.Y - e.Y;
break;
case 5:
this.Table.Paint += new PaintEventHandler(this.RedrawRedCard2);
IsTaken = 5;
OffsetX = RedCard2.Position.X - e.X;
OffsetY = RedCard2.Position.Y - e.Y;
break; } }
void MoveCard(object sender, MouseEventArgs e) {
switch (IsTaken) {
case 0:
if (IsCursorOverCard(e.X, e.Y) == 0)
Table.Cursor = Cursors.Default;
else
Table.Cursor = Cursors.Hand;
break;
case 1:
RedCard.Position.X = e.X + OffsetX;
RedCard.Position.Y = e.Y + OffsetY;
Table.Invalidate();
break;
case 2:
BlueCard.Position.X = e.X + OffsetX;
BlueCard.Position.Y = e.Y + OffsetY;
Table.Invalidate();
break;
case 3:
GreenCard.Position.X = e.X + OffsetX;
GreenCard.Position.Y = e.Y + OffsetY;
Table.Invalidate();
break;
case 4:
YellowCard.Position.X = e.X + OffsetX;
YellowCard.Position.Y = e.Y + OffsetY;
Table.Invalidate();
break;
case 5:
RedCard2.Position.X = e.X + OffsetX;
RedCard2.Position.Y = e.Y + OffsetY;
Table.Invalidate();
break; } }
void PutCard(object sender, MouseEventArgs e) {
IsTaken = 0; }
MainForm() {
this.SuspendLayout();
this.Width = 1024;
this.Height = 768;
this.Controls.Add(this.Table);
this.Table.Location = new Point(0, 0);
this.Table.Size = new Size(400, 400);
this.Table.Paint += new PaintEventHandler(this.DrawTable);
this.Table.Paint += new PaintEventHandler(this.DrawCards);
this.Table.MouseDown += new MouseEventHandler(this.TakeCard);
this.Table.MouseMove += new MouseEventHandler(this.MoveCard);
this.Table.MouseUp += new MouseEventHandler(this.PutCard);
this.ResumeLayout(); }
static void Main() {
Application.Run(new MainForm()); } }
|
|
|
|
|
That does look quite ugly.
You need to start by reading at the builder pattern, to build up the objects (you had a switch statement in the constructor).Understanding and Implementing Builder Pattern in C#.
Then as for the rest of the code, I might just create a separate function to handle the types, because most of the operations are same.
case 1:
RedCard.Position.X = e.X + OffsetX;
RedCard.Position.Y = e.Y + OffsetY;
Table.Invalidate();
break;
case 2:
BlueCard.Position.X = e.X + OffsetX;
BlueCard.Position.Y = e.Y + OffsetY;
Table.Invalidate();
break;
That part of the code can be rewritten to, something like this,
private void updateCardPosition(Card card, int x, int y) {
card.Position.X = x;
card.Position.Y = y;
}
case 1:
updateCardPosition(RedCard);
Lastly, the Table.Invalidate(); gets called in each of the block, so you can bring it out of the switch statement.
So basically you need to rewrite the code a bit functional in nature. Otherwise your code looks fine to me, just the redundancy of the code which you have to remove.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I am receiving an unhandled exception of type 'System.ArgumentException' occured in System.Drawing.dll error. The additional information is 'Parameter is not valid.
This error just recently started occurring and it happens in the designer page in the InitializeComponent procedure.
All the forms have started showing this message when trying to create a text box, combo box etc.
The controls are dragged and dropped onto the form without any data binding or any special restrictions etc.
When I create a new project adding the exact same type of layout, the application seems to be working fine.
Google overs no solution to this problem.
|
|
|
|
|
|