QLCDNumber numbers can't be centered - c++

Why QLCDNumber numbers can't be centered when the number of digits is lower than the number of digits allowed in the parameters of QLCDNumber ?
Can I bypass this ?

As a workaround you can set the number of digits each time you set a new value :
ui->lcdNumber->display(value);
ui->lcdNumber->setDigitCount(QString("%1").arg(value).length());
Here QString("%1").arg(value).length() returns the number of digits in value. When you set it properly it would be aligned correctly.

Related

Custom slider control in MFC (visual studio)

I am making a slider control in visual studio in MFC, I want to set the range from 14 to 100 and step size should be 0.25 as 14.25, 14.50, 14.75 .
How can can make an custom slider control?
A CSliderCtrl wraps a trackbar control. As such, the former shares the same limitations with the latter. Specifically, the range is set through the TBM_SETRANGE message (or the TBM_SETRANGEMIN and TBM_SETRANGEMAX messages). Either message takes an integral value, so you cannot have the control operate on fractional values.
If you need the integral values supported by the control to represent fractional values, you will have to perform the mapping in client code (scaling and translation). Possible mappings are:
Set the range from 0 * 4 to (100 - 14) * 4 (i.e. 0 to 344). The control position x represents the value 14 + x / 4.
Set the range from 14 * 4 to 100 * 4 (i.e. 56 to 400). The control position x then represents the value x / 4.
In general, fractional values cannot accurately be represented when using floating point values. In this case, however, there is no loss in accuracy; any integer value divided by a power-of-two (such as 4) can be accurately represented by a floating point value (so long as the result is still in range).

How can I random 3 different position in an 4x4 Array

I have a task which is creating an Dungeon Escape game, based on a 4x4 array. I first have to create 3 different postion for E(Exit),K(Key) and P(Player). How can I random those 3 in 3 different position in an array ?
EDIT: I meant I need to find a way to random 3 DIFFERENT POSITION the neatest way. I already know about the rand() and srand thing.
Try to use rand function which is used to generate random number.
First of all you need to initialize random seed with srand(time(NULL)). myRandomNum = rand() % 4; generate number between 0 and 3.
So, you can generate two number which would represent row index and column index and repeat that three times for: E(exit), K(key) and P(Player).

compress 4 byte floating point data to 1 byte

I need to compress floating point numbers (4 bytes) to 1 byte(0 to 0xFF) to send to another device. The floating point numbers range from -100000.0 to 100000.0.
The other device will decode from 1 byte back to floating point numbers. How do it do it with minimum data loss?
Thanks, JC
One solution is to use quantization. Divide 100000 to 127 intervals. Send the interval number to which float belongs to and a sign in lowest or highest bit
In your case the interval = 787,4
For example, you have input like 100. Send 1. Input 1000,147732. Send 2
On the device you can restore number by its interval.
The easiest solution is to restore the number as a middle of the interval. For example, every float that belongs to the first interval will be restored as 393.7
If you have some stats for digits distribution and it's not uniform, you can play around it by changing the intervals length and quantize frequent floats more precisely

Rounding a value contained within a CString

So I have a CString which contains a number value e.g. "45.05" and I would like to round this number to one decimal place.
I use this funcion
_stscanf(strValue, _T("%f"), &m_Value);
to put the value into a float which i can round. However in the case of 45.05 the number i get is 45.04999... which rounds to 45.0 where one would expect 45.1
How can I get the correct value from my CString?
TIA
If you need a string result, your best bet is to find the decimal point and inspect the two digits after it and use them to make a rounded result. If you need a floating-point number as a result, well.. it's hopeless since 45.1 cannot be represented exactly.
EDIT: the nearest you can come to rounding with arithmetic is computing floor(x*10+0.5)/10, but know that doing this with 45.05 WILL NOT and CAN NOT result in 45.1.
You could extract the digits that make up the hundredths and below positions separately, convert them to a number and round it independently, and then add that to the rest of the number:
"45.05" = 45.0 and 0.5 tenths (0.5 can be represented exactly in binary)
round 0.5 tenths to 1
45.0 + 1 tenth = 45.1
don't confuse this with just handling the fractional position separately. "45.15" isn't divided into 45 and .15, it's divided into 45.1 and 0.5 tenths.
I haven't used c++ in a while but here are the steps I would take.
Count the characters after the Decimal
Remove the Decimal
cast the string to an Int
Perform Rounding operation
Divide by the (number of characters less one)*10
Store result in a float

How to create data fom image like "Letter Image Recognition Dataset" from UCI

I am using letter_regcog example from OpenCV, it used dataset from UCI which have structure like this:
Attribute Information:
1. lettr capital letter (26 values from A to Z)
2. x-box horizontal position of box (integer)
3. y-box vertical position of box (integer)
4. width width of box (integer)
5. high height of box (integer)
6. onpix total # on pixels (integer)
7. x-bar mean x of on pixels in box (integer)
8. y-bar mean y of on pixels in box (integer)
9. x2bar mean x variance (integer)
10. y2bar mean y variance (integer)
11. xybar mean x y correlation (integer)
12. x2ybr mean of x * x * y (integer)
13. xy2br mean of x * y * y (integer)
14. x-ege mean edge count left to right (integer)
15. xegvy correlation of x-ege with y (integer)
16. y-ege mean edge count bottom to top (integer)
17. yegvx correlation of y-ege with x (integer)
example:
T,2,8,3,5,1,8,13,0,6,6,10,8,0,8,0,8
I,5,12,3,7,2,10,5,5,4,13,3,9,2,8,4,10
now I have segmented image of letter and want to transform it into data like this to put recognize it but I don't understand the mean of all value like "6. onpix total # on pixels" what is it mean ? Can you please explain the mean of these value. thanks.
I am not familiar with OpenCV's letter_recog example, but this appears to be a feature vector, or set of statistics about the image of a letter that is used to classify the future occurrences of the letter. The results of your segmentation should leave you with a binary mask with 1's on the letter and 0's everywhere else. onpix is simply the total count of pixels that fall on the letter, or in other words, the sum of your binary mask.
Most of the rest values in the list need to be calculated based on the set of pixels with a value of 1 in your binary mask. x and y are just the position of the pixel. For instance, x-bar is just the sample mean of all of the x positions of all pixels that have a 1 in the mask. You should be able to easily find references on the web for mathematical definitions of mean, variance, covariance and correlation.
14-17 are a little different since they are based on edge pixels, but the calculations should be similar, just over a different set of pixels.
My name is Antonio Bernal.
In page 3 of this article you will find a good description for each value.
Letter Recognition Using Holland-Style Adaptive Classifiers.
If you have any doubt let me know.
I am trying to make this algorithm work, but my problem is that I do not know how to scale the values to fit them to the range 0-15.
Do you have any idea how to do this?
Another Link from Google scholar -> Letter Recognition Using Holland-Style Adaptive Classifiers