|
EmuguCV is jsut a .NET wrapper around OpenCV.
That C++ code is just creating 3 Matrix instances and initializing them with all the values are each matrix position. The underlying code implements this as arrays.
Keep in mind that I haven't touched C++ in a really long time and have never used EmuguCV or OpenCV. But, in C#, I think the equivalent would be something like
Matrix R_x = new Matrix<double>(3, 3) {
1, 0, 0,
0, Math.Cos(theta[0]), -Math.Sin(theta[0]),
0, Math.Sin(theta[0]), Math.Cos(theta[0])
}
|
|
|
|
|
fyi: a literal translation of the first matrix to C#:
double[] theta = new double[]{0.4444};
Double[,] MatR_X = new double[3, 3]
{
{ 1.0, 0.0, 0.0 },
{ 0.0, Math.Cos(theta[0]), -Math.Sin(theta[0])},
{ 0.0, Math.Sin(theta[0]), Math.Sin(theta[0])}
}; However, you'll probably want to use the built-in Matrix3D Structure facilities in System.Windows.Media.Media3D: [^].
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I have a Polynomial class, which has integer coefficients and an integer field called Characteristic. When positive, the Characteristic value denotes that the coefficients represent elements of the integers mod Characteristic. What I would like is for type checking to consider Polynomials with different Characteristic values to be different types - it shouldn't be possible to do operations between Polynomials with unlike characteristics, and it would be nice if the characteristic were very visible rather than buried inside the object state, for example. I would use a syntax like Polynomial<3> to declare a Polynomial of characteristic 3, but barring that possibility, what else could I try? I can't explicitly declare classes for each characteristic I need, because I don't know which ones I'll need until runtime.
|
|
|
|
|
About the best I can suggest is C# 7.0 is constant type checking: is (C# Reference) | Microsoft Docs[^]
if (o is Polynomial p && p.Characteristic == 3)
{
... Messy, but ...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I happened across a way I might theoretically make the modulus value part of the type, but it's messier than your suggestion by a very wide margin: give Polynomial a type parameter that takes an Enum, generate an Enum at runtime whose number of elements is equal to the desired modulus using EnumBuilder, pass that to Polynomial, and use GetValues().Length or something to extract the modulus value. Definitely not worth it, haha.
Really, the important thing is that now I have a vote of confidence that there isn't an obvious "correct" way to handle it that I've missed.
|
|
|
|
|
Occam's Razor says: "Nope!"
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
My first thought was of using an Enum, keeping in mind that an Enum can have values that are not explicitly named: i.e.:
public enum PolyCharacteristicValue : Int32
{
NoCharacteristic = -1
}
public class Poly
{
public Poly(Int32 characteristic)
{
Characteristic = (PolyCharacteristicValue) characteristic;
}
public Poly(PolyCharacteristicValue characteristic)
{
Characteristic = characteristic;
}
public PolyCharacteristicValue Characteristic { set; get; }
}
Poly polyNoChar = new Poly(-1);
Poly polyT0 = new Poly(0);
Poly polyT99 = new Poly(99); Sketch: Then in some extension method:
public static class PolyExtensions
{
public static Poly PolyAdd(this Poly p1, Poly p2)
{
if (p1.Characteristic != p2.Characteristic)
{
throw new InvalidEnumArgumentException();
}
Poly newPoly = new Poly(p1.Characteristic);
if (p1.Characteristic == PolyCharacteristicValue.NoCharacteristic)
{
return newPoly;
}
return newPoly;
}
} The second idea would be to use a nullable Int in much the same way.
Would having the ability to compare two Polys, and do something if one of them's Enum value was greater, or lesser, than the other's be of any use ?
I am unclear if there's a relationship between the possible number of integer terms in the Polynomial and what is shown here as an Enum.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 8-Apr-18 11:07am.
|
|
|
|
|
Why can't you use an enum as the characteristic. At that point, it's the enum parameter reflects the value.
public enum PolyCharType { Type1=1,Type2,Type3=3};
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Do you envision having Polynomial be a generic type, to which the enum gets passed as the parameter? I could do that. The wrinkle is that the desired characteristic values aren't statically known, so I'd have to generate the enums at runtime. I gather that it is possible to do this.
|
|
|
|
|
You weren't clear on when this "type checking" should occur: compile time or run time.
Big difference.
Run time code can be very intelligent with a very small interface.
A (dynamic) "property bag" can imply type via the existence (or absence) of a given property; with "methods" added on the fly.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I was thinking compile time - my IDE underlining it in red if I tried to add two polynomials of unlike characteristic. Unless I'm missing something, runtime checks would only need to involve a field for the characteristic in the Polynomial class, and comparing the values in it at the top of each method that takes multiple Polynomials.
The place where I really started to wish compile time type checking reflected the characteristic was not to constrain what a caller can do, but to check myself while writing a very complicated method that generates many Polynomials of different characteristics internally in service of the calculation it needs to do.
|
|
|
|
|
Null and "something" is always null.
I would use the same philosophy here.
It's up to the "client" to make valid calls; the "server" just needs to keep from crashing.
Otherwise, use "type info" in the class. There is no "wrong" answer; only more or less coding.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Alexander Kindel wrote: The place where I really started to wish compile time type checking reflected the characteristic was not to constrain what a caller can do, but to check myself If you use over-ridden arithmetic operators, as shown in my first response to you, the parameter types of the arguments, and the specified return type, will effectively act as constraints.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
First time posting so please forgive me if I'm doing something wrong. I've read through the guidelines and have attempted many times to research this issue.
I'm attempting to use a C# script in SSIS to consume a JSON feed from a website. I found an amazing tutorial/blog which shows exactly what needs to be done. I've attempted to follow it step-by-step but the program keeps failing when it attempts to deserialize the JSON object. It fails with the below error message. Despite my best attempts, I can't figure out what I'm doing wrong, or if the JSON string has extra "stuff" that's messing with the deserialization. Any ideas?
Exception thrown: 'System.ArgumentException' in System.Web.Extensions.dll
JSON and SSIS Tutorial: Dennis and Jim's SSIS and BI Blog: Using a JSON Feed as a Data Source in SSIS[^]
Website JSON documentation: Card Objects · API Documentation · Scryfall Magic Card Search[^]
JSON Address: "https://api.scryfall.com/cards?"
JSON Class Generator: json2csharp - generate c# classes from json[^]
Code:
private Card[] GetWebServiceResult(string wUrl)
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(wUrl);
HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();
Card[] jsonResponse = null;
try
{
if (httpWResp.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = httpWResp.GetResponseStream();
string jsonString = null;
using (StreamReader reader = new StreamReader(responseStream))
{
jsonString = reader.ReadToEnd().Replace("\\", "");
reader.Close();
}
JavaScriptSerializer sr = new JavaScriptSerializer();
jsonResponse = sr.Deserialize<Card[]>(jsonString);
}
else
{
FailComponent(httpWResp.StatusCode.ToString());
}
}
catch (Exception e)
{
FailComponent(e.ToString());
}
return jsonResponse;
}
private void FailComponent(string errorMsg)
{
bool fail = false;
IDTSComponentMetaData100 compMetadata = this.ComponentMetaData;
compMetadata.FireError(1, "Error Getting Data From Webservice!", errorMsg, "", 0, out fail);
}
}
#endregion
#region JSON Class
public class ImageUris
{
public string small { get; set; }
public string normal { get; set; }
public string large { get; set; }
public string png { get; set; }
public string art_crop { get; set; }
public string border_crop { get; set; }
}
public class Legalities
{
public string standard { get; set; }
public string future { get; set; }
public string frontier { get; set; }
public string modern { get; set; }
public string legacy { get; set; }
public string pauper { get; set; }
public string vintage { get; set; }
public string penny { get; set; }
public string commander { get; set; }
public string __invalid_name__1v1 { get; set; }
public string duel { get; set; }
public string brawl { get; set; }
}
public class RelatedUris
{
public string tcgplayer_decks { get; set; }
public string edhrec { get; set; }
public string mtgtop8 { get; set; }
}
public class PurchaseUris
{
public string amazon { get; set; }
public string ebay { get; set; }
public string tcgplayer { get; set; }
public string magiccardmarket { get; set; }
public string cardhoarder { get; set; }
public string card_kingdom { get; set; }
public string mtgo_traders { get; set; }
public string coolstuffinc { get; set; }
}
public class AllPart
{
public string @object { get; set; }
public string id { get; set; }
public string name { get; set; }
public string uri { get; set; }
}
public class Datum
{
public string @object { get; set; }
public string id { get; set; }
public string oracle_id { get; set; }
public List<object> multiverse_ids { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("uri")]
public string Uri { get; set; }
public string scryfall_uri { get; set; }
public string layout { get; set; }
public bool highres_image { get; set; }
public ImageUris image_uris { get; set; }
public double cmc { get; set; }
public string type_line { get; set; }
public string oracle_text { get; set; }
public string mana_cost { get; set; }
public string loyalty { get; set; }
public List<object> colors { get; set; }
public List<object> color_identity { get; set; }
public Legalities legalities { get; set; }
public bool reserved { get; set; }
public bool reprint { get; set; }
public string set { get; set; }
public string set_name { get; set; }
public string set_uri { get; set; }
public string set_search_uri { get; set; }
public string scryfall_set_uri { get; set; }
public string rulings_uri { get; set; }
public string prints_search_uri { get; set; }
public string collector_number { get; set; }
public bool digital { get; set; }
public string rarity { get; set; }
public string illustration_id { get; set; }
public string artist { get; set; }
public string frame { get; set; }
public bool full_art { get; set; }
public string border_color { get; set; }
public bool timeshifted { get; set; }
public bool colorshifted { get; set; }
public bool futureshifted { get; set; }
public int edhrec_rank { get; set; }
public RelatedUris related_uris { get; set; }
public PurchaseUris purchase_uris { get; set; }
public string flavor_text { get; set; }
public string usd { get; set; }
public int? story_spotlight_number { get; set; }
public string power { get; set; }
public string toughness { get; set; }
public List<AllPart> all_parts { get; set; }
public string eur { get; set; }
public string watermark { get; set; }
}
public class Card
{
public string @object { get; set; }
public int total_cards { get; set; }
public bool has_more { get; set; }
public string next_page { get; set; }
public List<Datum> data { get; set; }
}
#endregion
|
|
|
|
|
If it doesn't work, go back to where you got the tutorial from, and ask there. If it's their code that doesn't work, it needs to be fixed. If it's that you haven't understood it, maybe they can improve the clarity.
But asking a random website that has nothing to do with the tutorial is just silly!
And ... you have to accept that most internet tutorials are pretty poor anyway: Don't Hit Save - Welcome To The Tutorial[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You know, calling CodeProject a "random website" might offend someone!
This site is filled with incredibly knowledgeable members, including yourself. This may be my first time posting, but I have scoured this site for years getting answers to many of my questions. It has an amazing community. I'm not choosing to post here by happenstance.
I'll agree that most tutorials are poorly written, but this one is not. It's actually far better than most. You are right that asking the original author makes sense, but the blog was written 5 years ago so expecting any response, let alone in a reasonable time frame is equally silly. Regardless, I've taken your suggestion and posted on his site linking to this one.
That said, my issue isn't with the content of the tutorial, but with my ability to debug the code "sr.Deserialize<card[]>(jsonString)". In the debug options, I've turned off "Enable Just My Code" and have the debugger loading all symbols, but I still can't actually see it deserialize so I don't know what's tripping up the program. If you can help with the debugger visibility then perhaps I can make some progress.
|
|
|
|
|
You need to "partition" your problem (better).
You're retrieving a string; deserializing it; etc.
You need to confirm what the actual contents of the string are. (Is it "formed" correctly?)
Then you attempt to deserialize just that string.
Visual Studio can generate classes from xml and json strings.
I KNOW that VS generates classes that work; I cannot speak for any other "tools".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks for your feedback, Gerry. I wasn't aware that VS could generate the JSON classes. That's awesome! I had to reinstall VS to get the VS paste special->Paste JSON as Classes to appear, but it the command works now.
I think I understand the root cause of my issues now, but I'm still not quite sure the best way to resolve it. I know you say that the VS generated classes work, but it's actually generating classes that don't compile. This is because there is a field called "name" and a field called "set_name", so "name" definition line fails with the following error:
"The type 'Datum' already contains a definition for 'set_name'". Please see the below code.
I did try getting around this by using [JsonProperty("name")] and capitalizing the field. It made it compile, but it's still failing when I run it.
Is there another way I can get around this in the class definition, or should I somehow figure out how to update the JSON string without messing with the rest of the data before attempting to deserialize it?
public class Datum
{
public string name { get; set; }
public string uri { get; set; }
public string set_name { get; set; }
public string set_uri { get; set; }
}
|
|
|
|
|
"set_name" is the "setter" being generated (by the compiler) as a result of "name" being defined as a property.
Stick with the attributes; just "rename" "set_name" or "name" or "both" ... I think you get the idea.
(You might get by by changing "name" to a public "field"; but it may not deserialize. Try it.)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 8-Apr-18 12:16pm.
|
|
|
|
|
Thanks Gerry.
It looks like I was using the property correctly.
The issue I was having was that I was trying to store the deserialized JSON into Card[] instead of just Card. That's why it kept failing for me.
I fixed that issue and everything magically started working. Thanks again for looking at it.
|
|
|
|
|
Hello,
I have a problem with the button hover effect, i dont want effects at all when i hover, i tryed so many things but nothing work.
I want to look like this when hover:
Like This
And not like this(I want to remove this effect):
Not Like This
Can anybody help?
Thank you all
|
|
|
|
|
You have to edit the button template to do that. That's a XAML problem, not a C# one.
This space for rent
|
|
|
|
|
.IsEnabled = false;
If not, you are violating common access conventions. This cannot be tolerated.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
The entire flat button, no area segregation by colour violates common sense.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Or maybe it's just a really big button.
(It's what happens when you default to "Stretch").
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|