|
Just plain brilliant, i didn't think of that! I'll have an attempt at that today. Thank you for the direction!
I'll try something like this and pray that it does what id'e like.
static void Main()
{
Bitmap img1 = new Bitmap("Lenna50.jpg");
Bitmap img2 = new Bitmap("Lenna100.jpg");
if (img1.Size != img2.Size)
{
Console.Error.WriteLine("Images are of different sizes");
return;
}
float diff = 0;
for (int y = 0; y < img1.Height; y++)
{
for (int x = 0; x < img1.Width; x++)
{
Color pixel1 = img1.GetPixel(x, y);
Color pixel2 = img2.GetPixel(x, y);
diff += Math.Abs(pixel1.R - pixel2.R);
diff += Math.Abs(pixel1.G - pixel2.G);
diff += Math.Abs(pixel1.B - pixel2.B);
}
}
I found this chunk of code online, and i believe that it would get the job done with some nasty fiddling. I would need to actually break this down and throw it into the search of my screen right?
modified 3-Feb-20 11:20am.
|
|
|
|
|
Yes; that would give an indication of how different the bitmaps are - but it won't be very fast, and may break if the sword is drawn a pixel higher then where you expect it to be.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Attempting this bit instead. Its going need a ton of modification in my existing code but i think i can make it work.
public static bool CompareBitmapsFast(Bitmap bmp1, Bitmap bmp2)
{
if (bmp1 == null || bmp2 == null)
return false;
if (object.Equals(bmp1, bmp2))
return true;
if (!bmp1.Size.Equals(bmp2.Size) || !bmp1.PixelFormat.Equals(bmp2.PixelFormat))
return false;
int bytes = bmp1.Width * bmp1.Height * (Image.GetPixelFormatSize(bmp1.PixelFormat) / 8);
bool result = true;
byte[] b1bytes = new byte[bytes];
byte[] b2bytes = new byte[bytes];
BitmapData bitmapData1 = bmp1.LockBits(new Rectangle(0, 0, bmp1.Width, bmp1.Height), ImageLockMode.ReadOnly, bmp1.PixelFormat);
BitmapData bitmapData2 = bmp2.LockBits(new Rectangle(0, 0, bmp2.Width, bmp2.Height), ImageLockMode.ReadOnly, bmp2.PixelFormat);
Marshal.Copy(bitmapData1.Scan0, b1bytes, 0, bytes);
Marshal.Copy(bitmapData2.Scan0, b2bytes, 0, bytes);
for (int n = 0; n <= bytes - 1; n++)
{
if (b1bytes[n] != b2bytes[n])
{
result = false;
break;
}
}
bmp1.UnlockBits(bitmapData1);
bmp2.UnlockBits(bitmapData2);
return result;
}
I believe i can make it work though. Hopefully. This would be faster right?
modified 3-Feb-20 15:05pm.
|
|
|
|
|
Face-recognition and OCR (text-recognition) usually use a AI trained for recognizing. There's some articles on CodeProject that do so, often using Emgu VC.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Alright thank you. Ill go dive into the face recognition side of things. I guess my project is going to have to wait a while to be worked on haha. Thanks again!
|
|
|
|
|
My pleasure
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
"Bitmap" recognition instead of "face" recognition? Sounds like the same reading department.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I mean basically the same idea, yeah!
|
|
|
|
|
see my code first
var data = dtFilterDataFromAllData.AsEnumerable().Where(x => x.Field<string>("Tab").ToString().Trim() == strBRTab
&& x.Field<string>("Broker Items").ToString() == strBRLineItem
&& x.Field<string>("Row").ToString().Trim() == RowNumber)
.Select(w => new { LinkText = w.Field<string>("LinkedItemList"), AllowBlank = w.Field<string>("Allow Blank in Calc.") }).ToList();
where i am using LINQ on datatable to select data for two fields called LinkedItemList & Allow Blank in Calc.
without using foreach how to read value from LinkText and Allow Blank in Calc.
array like access ?
how to read data like data[0]["LinkedItemList"]
please tell me the way without foreach or for. thanks
|
|
|
|
|
What type is data? It should have a property for LinkText and AllowBlank since you filled those in in your Select.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
You should ask this only in the LINQ forum, and wonder why.
<later>
var foo = data.FirstOrDefault();
foo.?
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
modified 31-Jan-20 21:16pm.
|
|
|
|
|
Mou_kol wrote: please tell me the way without foreach or for. thanks Use a while-statement, or a do-loop.
If you select a list, you'll have to go through it. If you want something more specific, be more specific in your query.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
soo im gonna try this once again
i have a job which is called "a dungeon"
The game assumes the existence of a map of the dungeon where the hero / heroine is, and
you want to escape from. The map is created by the programmer and the player does not know the
map.
It is known that the dungeon has 5 divisions. On the map, each of the dungeon divisions is
encoded by a sequence of 5 integers (INSWE) and a String.
The first of the five integers, I, is the numerical identifier of the division.
The remaining four integers N S W E represent the identifier of the division you are going to
the hero / heroine when advancing in one of the four cardinal directions (North, South, West, East).
If the value is zero it means that this direction has no output; 99 indicates the
dungeon (and game over)
after looking at it carefully and suggestion from my colleagues and teacher is the use of a mtraix to make the map (but not show it to the player) and some of my problems atm is kinda of connecting the matrix i have generated/choose and the change of room indidcationg that for example "on this room there is 2 exist one to the east and the other to the north"
in case you need some code to understand im not asking without even trying
s1 = {1,0,0,2, 3}
s2 = {2,0,0,0,1}
s3 = {3,0,4,1,5}
s4 = {4, 3,0,99,0}
s5 = {5,0,0,3,0}
this is the technicall map of the dungeon where you start in S1 which would be room 1 and would have the warning of a exit to the west(s2) and to the east(s3) as in the whole thing is
5 integers (INSWE)
I indicator - in this case it would be 1
N - north which in this situation is 0 indicating there is no pathway in that direction and its just a wall
S- south and see commentray above
W-west where they move from S1 to room 2 S2 where they will be presented with a new number of directions
------------------------------------------------------------------------------
if (S1[1] =/= 0) => "north"
if (S1[2] =/= 0) => "sul"
this is a system i considered for the case of making it easy on myself for the map like
in matrix S1[1] or matrix [1][1] if the value is not 0 well you can move in that direction
and of course i would most likelly put a else on the end of each just so in case it was a 0 they would give the same message saying to the player you cnat go in that direciton pls choose another option
---------------------------------------------------
so this is my basic ideas and hope any of you can help me/understand what i want to do
|
|
|
|
|
Posting the same thing in multiple places wastes our effort and that annoys people. You have this lack-of-a-question in QA so repeating here is not a good idea.
Particularly when you don't ask a question!
Quote: this is my basic ideas and hope any of you can help me/understand what i want to do
You have shown how you think you might solve it, but you haven't explained what problem you are having with that - we don't know what help you need.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What is your question?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I'm setting up an app that uses a FileSystemWatcher. When a file is added, modified, or removed, some processing has to be done. This processing includes saving a copy of the file in a secure folder and logging it to a database. It's possible for multiple users to access the same folder at the same time.
What I need is to be able to handle EVERY change to a file, no matter how quickly they happen. So if 3 different users drop a file called MyFile.doc into the folder, I need to handle that as 3 different versions of the same file. The problem is how to handle multiple people manipulating the file at the same time.
So, I'm looking for ideas on how to handle the concurrency issues that are going to arise.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 28-Jan-20 12:34pm.
|
|
|
|
|
Kevin Marois wrote: So if 3 different users drop a file called MyFile.doc into the folder, I need to handle that as 3 different versions of the same file. Regardless of the FileSystemWatchers' capabilites, I don't think the FileSystem supports that.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
modified 28-Jan-20 13:46pm.
|
|
|
|
|
Set up File Watcher to queue every change / event; have a separate thread process the queue (BG worker).
File Watcher starts the "queue watcher" any time it queues and the queue watcher is not active.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi,
I have used FileSystemWatcher a long time ago, and wasn't impressed by it. IIRC, when a file is being created, you get an event, after an unpredictable delay that is; and I saw no way to detect the end of the file writing, e.g. there is no close event.
So my apps ended up using one of two techniques:
- either use a delay after the create event to make somewhat sure the new file had entirely been written, not elegant at all;
- or, when I was in control of the file creation, simply create the file, then create a very small second file, and use FSW to only track the latter.
|
|
|
|
|
Quote: I have used FileSystemWatcher a long time ago
Things change.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I think you might be stuck with a polling mechanism rather than a watcher. If extensive security isn't a concern you can run a nice quick file hash (like MD5) periodically.
Really the only other thing I can think of is forcing users to manipulate the files in question through a specific pipeline that you can attach hooks to. I suppose you could do it as an Office extension and process changes through a queuing system, maybe going through something like RabbitMQ, redis, or Kafka. That'd be low-hanging fruit if you already use one of those services in your environment.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
dynamic returnObject = new ExpandoObject() as IDictionary<string, object>;
var EnterData = (IDictionary<string, object>)returnObject
EnterData.Add("myColumn", typeof(int));
Now when I debug a test that I have created I can see the value type has been set to int.
but I would like to add a test to this, purely for my own learning
var keypair = EnterData.FirstOrDefault(p=> p.Key == "myColumn");
var properties = keypair.GetType().GetGenericArguments();
var ValueType = properties[1];
which always returns a type object, is there a way to get the type that I have assigned to the keyvaluepair?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Maybe I'm doing or reading it wrong, but wouldn't that be
string myValueType = keypair.Value.ToString();
That should return "System.Int32", and the first part of the pair is always a string.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thanks Eddie, it worked..
Silly me, while looking my brain thought everything must complicated so I ignored all the easy stuff.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
You're welcome, and happens to us all
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|