|
Hi,
i am creating a application where i need to input a image and to count the number of red color in image (user will fill the color using red color pen in few boxes. Other parts of image are in black and white except the box)
E.g: Total 10 lines are there in a image
Each line has 3 box
user may fill any 1 of the box with red color
Is there any possibility of getting location (x,y) and count of the red color?
if anybody reply to this would be really helpful to continue the project
|
|
|
|
|
|
You can get the RGB values, but given that, its not easy to detect the actual color.
Brightness and luminosity tend to play a major role.
Plus there is the alpha value as well.
|
|
|
|
|
I wonder if your "bigger picture" goal here is: to determine, for each of the ten "lines," which ones of the boxes are "filled."
To help you achieve this without scanning every single pixel in the image, and doing some complex analysis (the worst case), I think we need to know exactly what you can assume about the image you have to analyze:
1. is the image guaranteed to be "linear:" i.e., there's no distortion, warping, no perspective effect ? is there a significant "noise factor," or variation in overall image brightness, or color-cast ?
2. is the relative position of the boxes which can be filled the same on each instance of the image you need to analyze ?
3. is the relative position of the boxes which can be filled the same from line to line. ?
5. what, exactly, constitutes a "valid fill" ? if there's even one pixel of red inside a box, does that make it "selected" ?
6. is the fill-color value of "red" the same for each image ?
Depending on the degree of regular structure in the images to be analyzed, then you can approach this problem in different ways.
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I did a project recently on real-time color detection.
The major issue is how to actually define a color as you see it , not as a computer sees it. for that you need to do some math.
as you currently understand an image, it is a 3d array with RGB values. R G B are actually just three linearly independent vectors used to define any color in the color space (r[0-255]g[0-255]b[0-255]). Think of it as X Y Z coordinates in space. a specific color is just a point in this space. it is nearly impossible to get the same color in real life cases. so rather than matching a point in space , you can make a small volume around that point , lets say r+-5 g+-5 b+-5 and see if the given color falls in the defined space or not.
another approach is to make a new coordinate system with your color as a primary vector. now you again define the whole color range with these new vectors BUT now the higher the value of your required vector tell you that more of your color is present. if the other two orthogonal vectors have components close to 0 than its perfectly your color and you can mark it as ok. This gives you a trivial solution to
BillWoodruff wrote: 6. is the fill-color value of "red" the same for each image ?
and as Bill asked, your problem can have a lot of approaches depending on what you actually want to achive
good luck
|
|
|
|
|
Be care who you reply to. You didn't reply to the OP, you replied to Bill. The OP will now never get a notification that you posted anything in reply to his post. Bill gets that, and frankly, I think he knows what you just told him.
|
|
|
|
|
Hi
i have a method which takes around 10sec to excute(sometimes more time) and store the data in datatable. i am calling this metod inside a for loop so the process is taking longer time. Please suggest a way to speed up the process.
This method takes a input and generate a datarow and add that row to the global datatable. so there is same datatable which is being used throughout the for loop iterations. Please suggest how can i use thread in this case specially when we don't know how much time the method is going to take.
|
|
|
|
|
You need to identify if it is the building of the row or writing the row to the database that is causing the bottleneck. They require different solutions.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
No i am creating a datarow.there is no database. i am creating the datatable using that row.
public void GetData(DataTable dtAssetValues)
{
DataRow objdr = dtAssetValues.NewRow();
try { objdr["OSName"] = GetValues(strKey);
dtAssetValues.Rows.Add(objdr)
}
catch { }
}
here in this case the GetValues method has a Thread.Sleep(1000) of 1 sec. so there are 5-6 columns in the datatable for which i am calling this GetValues method to retrieve the column value.
I am calling this GetData method inside a for loop. Hope this helps.
|
|
|
|
|
superselector wrote: he GetValues method has a Thread.Sleep(1000) of 1 sec
You've now got my curiosity - why do you sleep the thread?
Also as a rule it is best not to catch exceptions without handling them - otherwise you may get undesired data/behaviour within the database.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Thanks.
Actually in that method, the response from a remote machine takes some time, hence i have added some delay in that method.
|
|
|
|
|
I still don't understand why you need a sleep, since if the response is taking some time the method will hold the thread - so there should be no need for a sleep.
Can you post the method that has the sleep to give me more of an idea of what you are trying to accomplish.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Well, that Thread.Sleep will explain why this takes so long. When you do Thread.Sleep, you block that thread and put it to sleep. What effect are you trying to achieve here?
|
|
|
|
|
Thread.Sleep is probably not the solution.
|
|
|
|
|
the requirement goes like this ... I have set of ip's . i am looping through the IP list and for each ip i am checking whether i can ping them , i have given a time out of 4 seconds for ping reply. and am storing the result in a datatable.Pleas let me know how it can be implemented using threading to make the looping faster without losing any data as most of the ips are taking 3-4 seconds for reply.
|
|
|
|
|
Ok, it's a little tricky.
The simplest way, not very good is: make one thread for every ping action, start them all, then Join them all. Is that good enough for you?
Otherwise, use ping.SendAsync, and make very sure that PingCompletedEventHandler is thread-safe. The handler will have to 1) save the result (safely! may involve locking) and 2) signal a waithandle (after saving the result). Then you can do a WaitAll over all the waithandles to continue when all the pings are done.
|
|
|
|
|
if i follow the first option, Do in need to specify any timeout in Thread.Join method.
|
|
|
|
|
If the pings have a timeout, that should not be necessary, though it wouldn't be a problem either (as long as it's high enough to give the pings time to succeed).
|
|
|
|
|
i think i need to specify timeout in join with more that 2500 ms as i have specified a time out of 2 sec. without any time out its very slow.
|
|
|
|
|
But sometimes the pings took 4 seconds, right?
superselector wrote: without any time out its very slow. Well that's weird, it shouldn't take significantly longer than the longest running ping. Could you show the code?
|
|
|
|
|
yes the time out takes 4 secs, i have given 2 secs for testing ... actually on successful ping checking for ping i am trying to get some basic details of that ip using WMI.WMI is taking some time also if its not enabled.
for (int index = startIP; index <= EndIP; index++)
{
ipVal = startSubnet + "." + index.ToString();
Thread wmithread = new Thread(() => PerformWMIOperation(ipVal.ToString().Trim(), txtUserName.Text.ToString().Trim(), txtPassword.Text.ToString(), txtDomain.Text.ToString(), dtAssetValues, chkImpersonate.Checked, recordnumber));
wmithread.Start();
wmithread.Join(2500);
}
|
|
|
|
|
Ok, not like that. Don't, "for every thread, start it, then join it". That just runs everything in serial. Do, "for every thread, start it. Then, for every thread, join it." That's how I said it: start them all then join them all.
|
|
|
|
|
Hi i did not understand do you want the code to be changed to
for (int index = startIP; index <= EndIP; index++)
{
ipVal = startSubnet + "." + index.ToString();
Thread wmithread = new Thread(() => PerformWMIOperation(ipVal.ToString().Trim(), txtUserName.Text.ToString().Trim(), txtPassword.Text.ToString(), txtDomain.Text.ToString(), dtAssetValues, chkImpersonate.Checked, recordnumber));
wmithread.Start();
wmithread.Join();
}
|
|
|
|
|
That wouldn't help. The problem is this:
superselector wrote: wmithread.Start();
wmithread.Join(); That's like calling that ping operation without a thread, except this way resources are wasted as well. Or to put it differently, it's like hiring a team to play a game of monopoly, in order to do it faster. That doesn't work. If everyone takes turns anyway, you might as well do it by yourself.
You need an array of threads. Fill the array, start them all, then, and only then, join them all.
Besides, what's with the WMI stuff? Do you need something that the Ping class[^] can't do?
|
|
|
|
|
can you please give a sample code to implement this
|
|
|
|