I use
Screen.PrimaryScreen.Bounds.Height
and
Screen.PrimaryScreen.Bounds.Width
To render my window (i.e it's a percentage with all buttons etc derived from this). Will this work as expected for dual screens? Are there any situations where it won't work as expected?
Thanks,
Richard
You might want to try
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width
to avoid problems with users who have larger task bars and things.
example usage of this method can be found on MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.primaryscreen.aspx
you may also find this of interest:
http://msdn.microsoft.com/en-us/library/ms812142.aspx
Related
Let's assume, that we're scanning test-like documents with checkboxes / empty circles (for signing / striking / ticking). What would be the proper way, to check, if already cropped checkbox/circle is checked/signed/striked/ticked?
In case we'll force test users to fully mark the area, just knowing the position of checkbox/circle and counting amount on non-white pixels would be enough (would it?), but what way should we approach to test, that the checkbox / circle is ticked or checked (X)?
This is going to be part of the project in C#, so code or even ready libraries for .net / c/c++ would be appreciated.
sorry for the shortness of this answer but you could have an ocr system run on the area within the checkbox.
If it returns nothing then you know it's not checked.
If it returns something then compare it against a large white list of possibilities and then flag uncertainties.
you could use the error handling that #dan proposed as well
What makes this more robust than just taking an average is that you can determine if it's not checked with a high certainty. because we're looking for a mark that is in some minimal way recognizable we know if there isn't anything there then it's definitely not checked. all you have to do then is find a good white list of characters and marks that could be used as checks (and think outside of the box, the ocr system may return an 'a' for a squiggle, but that is a positive response). And to clarify, the problem with just taking an average is that any increase in darkness in the check box yields a positive result, which isn't always the case. if someone puts a mark and then erases you're still going to have a increase in darkness within the box.
Lastly i'll add that there are a lot of OCR systems out there now that are pretty advanced. i doubt you'd have much trouble finding one where you could provide additional training data sets that would match you're cases better than random characters.
The algorithm would go something like this:
Find each checkbox (I understand you already have that)
Calculate the average of the color of all pixels
If it is above a certain threshold, it is marked, if below, it is unmarked
However, you should add some checks:
Are multiple above the threshold? -> Let a human check it, the student could have first ticked something and then changed it to another field.
Are none above the threshold? -> Let a human verify that really none have been checked.
I guess the important part about this answer is:
If the algorithm is unsure, flag it for manual processing.
Most of the high performance products that offer checkbox recognition use some kind of bell distribution curve to work out the likelihood of a box actually being checked: too much 'data' and there's a good chance the user changed their mind and has scribbled-out this box; too few and it could be the 'tail' left by a user ticking a box below and not lifting the pen before crossing the next box region.
I'd suggest you apply additional logic to deal with more than one box being allowed (e.g. do you own a car / do you also own a bike) as well as the situation where only one box can be correct (e.g. are you male or female). This should help your app. filter out the more obvious errors.
I'm looking for a way to convert a 2D array to the fewest possible rectangles like in this example:
X
12345678
--------
1|00000000
2|00011100
3|00111000
Y 4|00111000
5|00111000
6|00000000
to the corner coordinates of the rectangles:
following the (x1,y1);(x2;y2) template
rectangle #1 (4,2);(6,2)
rectangle #2 (3,3);(5,5)
There has been a similar question here before but unfortunately, the link provided in its answer is broken, and I cannot check it anymore.
I'd like to do this in C# but any kind of help is appreciated.
(It doesn't even have to be the fewest possible rectangles, but the fewer the better :) )
Thanks in advance!
I think that you are trying to cover a set of points in the 2D plane with the minimum required number of rectangles. An answer to Find k rectangles so that they cover the maximum number of points said that this was an NP-complete problem and linked to here (which works for me). A google search finds http://2011.cccg.ca/PDFschedule/papers/paper102.pdf.
There papers agree that rectangle covering is NP-complete but do not actually prove it, and the references for this seem to be unusually elusive - https://cstheory.stackexchange.com/questions/3957/prove-that-the-problem-of-rectilinear-picture-compression-is-np-complete
What I take from these documents is this:
It is unlikely that there is an affordable way of getting the absolutely best answer for large problems, so you might have to either spend a lot of time to get exact answers for problems that are in some sense small, by exhausting over all possible alternatives or perhaps using something like branch and bound, or settle for affordable methods - like greedy search, or beam search, or limited discrepancy search - which are not guaranteed to give you the absolutely best answer.
In this case there seem to be more restricted versions of this problem which are not NP-complete. You might possibly read a paper and find that there is some detail of your problem that means that this method applies to you. One example is "AN ALGORITHM FOR CONSTRUCTING REGIONS WITH RECTANGLES:
INDEPENDENCE AND MINIMUM GENERATING SETS
FOR COLLECTIONS OF INTERVALS*" by Franzblau and Kleitman - I found this in the ACM Digital Library, though - I don't know if it is generally accessible. It works for a restricted set of polygons.
This may help you get started. If you convert the binary data to numbers, you get this:
0
28
56
56
56
0
So where ever there are consecutive equal numbers, there is a rectangle.
I want to use drawString to print a sentance but some parts of it has to be bold. What is the best way to do this? Yes, I have considered using two drawString. But is there a intelligent way of using two drawStrings if we have to.
We cannot make any assumtion about the length of the sentance. However it is prepared in a format.
eg:
Say hello to name. Good afternoon
name.
Thanks
This is my old question on MSDN & it was answered. It works good. I hope it is the thing you want to find.
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/8a050039-d74a-4ab5-9237-98615e10e303
Yes, you will have to call DrawString twice - you can write a small wrapper class (or extension method) that will do that for you.
A Java version of this question was just answered, and, well, I don't know how to do this in .net.
So how do you calculate the display width of a string in C# / .net?
An alternative for Windows Forms is the static TextRenderer.MeasureText method.
Although restricted to integer sizes, this (in tandem with TextRenderer.DrawText) renders more accurate and much higher quality ClearType text than the Graphics.MeasureString/DrawString duo.
You've got the same problem in this question as was present in the Java question - not enough information! It will differ between WinForms and WPF.
For WinForms: Graphics.MeasureString
For WPF I'm not sure, but I suspect it will depend on the exact way you're drawing the text...
In WPF you would use FormattedText.
Graphics.MeasureString but its a bit crappy, as is explained and improved upon; here
You would use Graphics.MeasureString.
http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx
Graphics.MeasureString([text to measure],[font being used to measure text]);
The resulting object will provide the following:
Other overloads of MeasureString also available.
Alright quick overview
I have looked into the knapsack problem
http://en.wikipedia.org/wiki/Knapsack_problem
and i know it is what i need for my project, but the complicated part of my project would be that i need multiple sacks inside a main sack.
The large knapsack that holds all the "bags" can only carry x amount of "bags" (lets say 9 for sake of example). Each bag has different values;
Weight
Cost
Size
Capacity
and so on, all of those values are integer numbers. Lets assume from 0-100.
The inner bag will also be assigned a type, and there can only be one of that type within the outer bag, although the program input will be given multiple of the same type.
I need to assign a maximum weight that the main bag can hold, and all other properties of the smaller bags need to be grouped by weighted values.
Example
Outer Bag:
Can hold 9 smaller bags
Weight no more than 98 [Give or take 5 either side]
Must hold one of each type, Can only hold one of each type at a time.
Inner Bags:
Cost, Weighted at 100%
Size, Weighted at 67%
Capacity, Weighted at 44%
The program will be given an input of multiple bags, and then must work out combinations of Smaller Bags to go into the larger bag, there will be multiple solutions depending on the input, and the program would output the best solutions for me.
I am wondering what you guys think the best way for me to approach this would be.
I will be programming it in either Java, or C#. I would love to program it in PHP but i'm afraid the algorithm would be very inefficient for web servers.
Thanks for any help you can give
-Zack
Okay, well, knapsack is NP-hard so I'm pretty certain this will be NP-hard as well (if it weren't you could solve knapsack by doing this with only one outer bag.) So for an exactly optimal solution, you're probably going to be able to do no beter than searching all combinations. So the outline of the program you want will be like
for each possible combination
do
if current combination is better than best previous
save current combination as best so far
fi
od
and the run time will be exponential. It sounds, though, like you might be able to get a near solution with dynamic programming.
Consider using Prolog for your logical programming. There's multiple implementations of it including P# on mono (.NET). Theres a bit of a learning curve, but once you get used to it, it's pretty much in a league of its own for this kind of problem solving.
Hope this helps. Cheers!
link to P#