|
Wrong forum; this is an ASP.NET question.
|
|
|
|
|
my intention was to compare two images and get the diff images using Emgu CV library. this is can be done below way. here is bit of code for achieving my goal.
Image<Gray, Byte> img1 = new Image<Gray, Byte>("C:\\image1.png");
Image<Gray, Byte> img2 = new Image<Gray, Byte>("C:\\image2.png");
Image<Gray, Byte> img3 = img2 - img1;
now my intention to know how to merge diff images with first image as a result i will get another image which will look like second image.as example say i have two images 1st image is full green image and second image is full green but have red circle at middle right corner. when i got the diff image after subtract then how can i merge the diff portion with full green image as a result my new merge image will look like full green image with red circle at middle right corner. can u please suggest anything how to achieve it with EmguCV library.give me a sample code using EmguCV library.thanks
tbhattacharjee
|
|
|
|
|
Can I use small local method in program method in C#?
Like it is flexible in Pascal function in function.
And in which places can i make methods?
|
|
|
|
|
No, you can;t declare a formal method as local to a method:
public int OuterMethod(int i)
{
public int InnerMethod(int i)
{
return 1 * 2;
}
return InnerMethod(i) - 1;
} That is not allowed by the C# syntax.
You can use a lambda though: Lambdas[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
So recursion is it impossible to use?
Inconvenient to define many variables twice to see them in other place. And make many arguments to simple mechanical code.
|
|
|
|
|
Recursion is always possible, you don't need "local methods" for that:
public int factorial(int i)
{
if (i > 1) return i * factorial(i - 1);
return 1;
} As is mutual recursion:
public int A(int i)
{
if ((i & 1) == 0) return B(i - 1);
return i + 1;
}
public int B(int i)
{
if ((i & 1) == 1) return A(i * 2);
return i * 2;
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
You're welcome.
One way you might not have considered is to create a nested class: all instance methods have access to the class level fields (variables in Pascal), so instead of having your variables local to the pascal function and available to nested functions, you have them private to the class instance, and all methods in the nested class can access them, but the outside world can't:
public class MyClass
{
private class InnerClass
{
private int i = 0;
private int j = 1;
public InnerClass(int x)
{
j = x;
}
public int MethodOne(int x)
{
i = x;
return MethodTwo(j);
}
public int MethodTwo(int x)
{
return i * j + x * 2;
}
}
public void UseIt()
{
for (int i = 0; i < 10; i++)
{
InnerClass ic = new InnerClass(i);
Console.WriteLine(ic.MethodOne(i * 2));
}
}
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
In method of event ButtonClick I can create subclass and local method in it?
public class MyForm
{
private void button_Click(args)
{
private class InnerClass
{
private int i = 0;
private int j = 1;
public InnerClass(int x)
{
j = x;
}
public int MethodOne(int x)
{
i = x;
return MethodTwo(j);
}
public int MethodTwo(int x)
{
return i * j + x * 2;
}
}
InnerClass.MethodOne();
}
}
modified 18-Oct-14 5:49am.
|
|
|
|
|
No!
An event handler is just a method with a specific signature: you can't create classes local to methods either. Just create the new class as private to the class containing the Click handler, and then create an instance of the class in the button_Click method. You can then call the inner class methods on that instance.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ok. Thank you.
I have to redeclare all local variables and send many arguments to other class.
Or declare local variables in global class as global variables.
Sorry for Pascal-thinking.
|
|
|
|
|
No, you declare the variables that the methods must share as private members of the nested class - then they are available to all methods within the class, but not outside.
Each instance of the nested class gets it's own "set" of the variables, just the same as each call to a function in Pascal creates it's own set of variables local to the function and available to all nested functions within it.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ok. Ill do so.
Thank you again.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Ignorissimus' vote of #1 leavened with the yeast of #5
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
Thank you Bill!
How are you this (locally grey, wet, and miserable but probably for you it's) fine day?
All finished setting up the new house?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Note that C# does not, like Pascal, have a separate syntax for procedures (do not return a value) and functions (return a value): in C# both are termed "methods."
There's no direct equivalent in C# to Pascal's nested functions where the inner functions have access to the variables in their "container" ... if that's what you are asking.
What exactly do you mean by "in program method:" do you mean in the Program.cs class that in the default Windows Forms application contains the 'Main method ?
It's easier to say where you can't create methods:
1. outside a NameSpace
2. inside a Method
However, one can, in a way, create methods inside methods by creating instances of delegates or anonymous methods/lambda expressions. The 'Action and 'Func delegates are useful to define methods inside a method.
And, you can have nested Classes in .NET, with each Class containing methods: by making an inner Class static one can easily execute the method given an instance of the outer Class.
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
modified 18-Oct-14 4:39am.
|
|
|
|
|
BillWoodruff wrote: It's easier to say where you can't create methods:
1. outside a NameSpace
2. inside a Method
That's clear.
Thanks.
ill check later rest wide information
|
|
|
|
|
My DeepCopy method:
public static T DeepCopy<T>(T entity)
{
if (entity == null)
{
throw new ArgumentNullException("Entity cannot be null");
}
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, entity);
ms.Position = 0;
return (T)formatter.Deserialize(ms);
}
}
The entity I'm trying to copy:
[Serializable]
[DataContract]
public class SafetyInfractionEntity : _BaseEntity
{
#region Properties
private int _SafetyInfractionId;
[DataMember]
public int SafetyInfractionId
{
get { return _SafetyInfractionId; }
set
{
if(_SafetyInfractionId != value)
{
_SafetyInfractionId = value;
IsDirty = true;
RaisePropertyChanged("SafetyInfractionId");
RaiseEntityChanged();
}
}
}
private int _EmployeeId;
[DataMember]
public int EmployeeId
{
get { return _EmployeeId; }
set
{
if(_EmployeeId != value)
{
_EmployeeId = value;
IsDirty = true;
RaisePropertyChanged("EmployeeId");
RaiseEntityChanged();
}
}
}
private int _InfractionTypeId;
[DataMember]
public int InfractionTypeId
{
get { return _InfractionTypeId; }
set
{
if(_InfractionTypeId != value)
{
_InfractionTypeId = value;
IsDirty = true;
RaisePropertyChanged("InfractionTypeId");
RaiseEntityChanged();
}
}
}
private LookupEntity _InfractionType;
[DataMember]
public LookupEntity InfractionType
{
get { return _InfractionType; }
set
{
if (_InfractionType != value)
{
_InfractionType = value;
RaisePropertyChanged("InfractionType");
RaiseEntityChanged();
}
}
}
private DateTime? _InfractionDate;
[DataMember]
public DateTime? InfractionDate
{
get { return _InfractionDate; }
set
{
if (_InfractionDate != value)
{
_InfractionDate = value;
IsDirty = true;
RaisePropertyChanged("InfractionDate");
RaiseEntityChanged();
}
}
}
private int _JobRevisionId;
[DataMember]
public int JobRevisionId
{
get { return _JobRevisionId; }
set
{
if (_JobRevisionId != value)
{
_JobRevisionId = value;
IsDirty = true;
RaisePropertyChanged("JobRevisionId");
RaiseEntityChanged();
}
}
}
private int _ReportedByEmpId;
[DataMember]
public int ReportedByEmpId
{
get { return _ReportedByEmpId; }
set
{
if(_ReportedByEmpId != value)
{
_ReportedByEmpId = value;
IsDirty = true;
RaisePropertyChanged("ReportedByEmpId");
RaiseEntityChanged();
}
}
}
private string _Comments;
[DataMember]
public string Comments
{
get { return _Comments; }
set
{
if(_Comments != value)
{
_Comments = value;
IsDirty = true;
RaisePropertyChanged("Comments");
RaiseEntityChanged();
}
}
}
private JobEntity _InfractionJobLocation;
[DataMember]
public JobEntity InfractionJobLocation
{
get { return _InfractionJobLocation; }
set
{
if (_InfractionJobLocation != value)
{
_InfractionJobLocation = value;
RaisePropertyChanged("InfractionJobLocation");
}
}
}
#endregion
}
Using it like this:
private SafetyInfractionEntity originalSelectedInfraction;
.
.
.
private void editInfraction()
{
originalSelectedInfraction= Utilities.DeepCopy<SafetyInfractionEntity>(SelectedInfraction);
InfractionEditMode = EditMode.Edit;
refreshView();
}
It's not copying. Changes to SelectedInfraction also appear in the originalSelectedInfractioncopy.
Anyone see what I'm doing wrong?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
What kind of debugging have you done, and what do you see ?
If you set a break-point in 'DeepCopy at: ms.Position = 0; and examine what's in 'ms: what do you find: what you expected to find ?
Have you experimented with using a non-Generic 'DeepCopy, or, a non-static version, to see if that might make a difference ? What's in originalSelectedInfraction after the DeepCopy: anything ?
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
From what I can see, there's no way that changes in your original are going to show up in the copy, they are two completely distinct objects.
I'd check where else you are doing this:
originalSelectedInfraction = Utilities.DeepCopy<SafetyInfractionEntity>(SelectedInfraction);
Regards,
Rob Philpott.
|
|
|
|
|
That can only happen due to side-effects of other code which you did not show here. What does happen in the PropertyChanged event handlers? Do you "refresh" some data somewhen from the database?
|
|
|
|
|
Hi everybody,
I am new to c# and have a question that is rather related to wireshark or how to capture messages in plain text sent over the network.
I created a socket server and a tcpclient in c#. I am sending a message like "Here I am" over tcp using the client. The Server answers with a simple string like "Hello". I do this on a local ip address and port 7.
I see the messages in the command line (console), but Wireshark does not show me the text. I am filtering ip.adress source and ip.address dest, but the capture window is empty.
I appreciate any help.
Cheers
Lillepige
|
|
|
|
|
This question has more to do with Wireshark than C#. I suggest you go to their website to see how to use it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
What does this have to do with C#?
Chances are you didn't capture on the correct interface.
|
|
|
|