Android custom input component with graphical representation? - custom-component

I am looking all over the net to find out a code to make a custom input component that I need but didn't stumble upon anything similar. Here's how I'd like it to work:
the purpose is to input the quantity (a number)
the quantity is to be changed with two buttons (+ & -)
there should be a button to accept the input
Here's the tricky part - the graphical representation of the input:
I'd like to have two pictures representing the currently selected quantity in the following way:
q = 0:
Both pictures are dimmed
q = 1:
The upper-left quarter of the first picture is bright (normal) and the rest is dimmed
q = 2:
The upper half of the first picture is bright (normal) and the rest is dimmed
q = 3:
The upper half + lower-left quarter of the first picture is bright (normal) and the rest is dimmed
q = 4:
The first picture is bright and the second one is dimmed
q = 5:
The first picture is bright and the upper-left quarter of the second picture is bright
.
.
.
q = 8:
Both pictures are bright.
I hope I've explained that in an understandable way.
The question is:
Do I have to make 5 instances of each picture (dimmed, bright upper-left quarter, bright upper half, bright upper half + lower-left quarter, bright) or is it possible to have only one instance of each picture (bright) and to dim the portions (as necessary) with the code?
Of course, I'd appreciate a link to anything that would be of any help or chunk of the code.

I think you should be able to handle all of your conditions with just 2 images. But use a combination linearlayout,framelayout and imageviews. Some thing like this to represent one image.
FrameLayout
Imageview
LinearLayout (Divided to 4 cells using the weight property)
You can change the alpha value of the bg color of the linear layouts to get the dimmed effect.
This can also be done using different slices of the images and changing the alpha value of the imageview. You will need to find what suits you more. It wont be easy to find any code samples as this is not a common UI found in apps.

Related

Cropping the minimum sized rectangle of a shape from an image

I am making a card recognition project on MATLAB and I am stuck at this point. There are images of cards and on an image I want to define the smallest rectangle that takes the card inside. Example like below
Original image
Converted image
I am currently able to convert the image to black and white (leaves me only the cards white spaces), I want to define the rectangles by the whole white spaces. E.g., if I have 3 non-lapping cards in my image, I want to have 3 images like above (doesn't matter if another cards edge appears on the image, the important part is that rectangle must pass through the edges of the selected card).
I have tried edge definition methods but wasn't successful. Thanks for your help already.
I recommend you use regionprops function from the image processing tool box, i.e.,
bb = regionprops(yourImage, 'boundingbox');
which will return the bounding box. There is a nice MATWORKS video here and you can jump to about minute 26 for what you need.

Extract Rectangular Image from Scanned Image

I have scanned copies of currency notes from which I need to extract only the rectangular notes.
Although the scanned copies have a very blank background, the note itself can be rotated or aligned correctly. I'm using matlab.
Example input:
Example output:
I have tried using thresholding and canny/sobel edge detection to no avail.
I also tried the solution given here but it detects the entire image for cropping and it would not work for rotated images.
PS: My primary objective is to determine the denomination of the currency. There are a couple of methods I thought I could use:
Color based, since all currency notes have varying primary colors.
The advantage of this method is that it's independent of the
rotation or scale of the input image.
Detect the small black triangle on the lower left corner of the note. This shape is unique
for each denomination.
Calculating the difference between 2 images. Since this is a small project, all input images will be of the same dpi and resolution and hence, once aligned, the difference between the input and the true images can give a rough estimate.
Which method do you think is the most viable?
It seems you are further advanced than you looked (seeing you comments) which is good! Im going to show you more or less the way you can go to solve you problem, however im not posting the whole code, just the important parts.
You have an image quite cropped and segmented. First you need to ensure that your image is without holes. So fill them!
Iinv=I==0; % you want 1 in money, 0 in not-money;
Ifill=imfill(Iinv,8,'holes'); % Fill holes
After that, you want to get only the boundary of the image:
Iedge=edge(Ifill);
And in the end you want to get the corners of that square:
C=corner(Iedge);
Now that you have 4 corners, you should be able to know the angle of this rotated "square". Once you get it do:
Irotate=imrotate(Icroped,angle);
Once here you may want to crop it again to end up just with the money! (aaah money always as an objective!)
Hope this helps!

Way to get a color while transitioning

I thought about the whole transition thing, and also saw while a text's color is being transitioned - it crosses through other tints of colors.
I had a lot of situations when I saw a beautiful color which I wanted, but it was a part of the transition process, and I eventually couldn't accomplish it.
For example, this code:
HTML:
<div id="transition">
ultra super califragilisticexpialidocious
</div>
CSS:
#transition {
color:black;
transition: 1s color;
}
#transition:hover {
color:#f00;
}
A demo: JsBin
You could see the transition shows a maroon color while text is transitioned, and my meaning is, how can I get this special tint of maroon?
Generally, my question is, how can I get a color while it is transitioned? There's a way to pick it?
Thanks in advance
Well, the things we think we like most are often those that are hard to get ;-)
But it's not so hard in this case. The question is whether picking the transitioning color is the best way to get what you want. Wouldn't it be simpler to change the color by hand until it looks best?
This is how to easily change a displayed font color with the Firebug plugin of Firefox:
Open the page with the transition and open the Firebug window.
Select the HTML tab, and then the Style tab of the side panel (if the side panel is closed, open it by clicking on the small arrow in the top right corner).
Click on the button with the mouse pointer in the top left corner of the Firebug window, then click on the div with the transition, thus selecting it.
You may want to disable the transition in the style, by clicking to the left of it.
You may want to display colors in RGB instead of hex (you can toggle back and forth when you want), by clicking on the dropdown button in the Style tab and selecting the mode you want.
You can click on the color value to edit it. Instead of rewriting it, you can click again on a single component (works in hex mode too), and then use the up and down arrow keys. It's almost like having a slider for each component. If you have the whole value selected, the arrow keys change all three components simultaneously.
Chrome is almost identical in operation. You open the Developer Tools with Ctrl-Shift-I, select an element with the magnifier button, and edit its style. You can toggle between hex colors and RGB colors by clicking on the gear-wheel within the Styles window. The difference with Firebug is that you can only modify the single RGB values with the up and down arrow keys when in RGB mode, in hex mode the arrow keys can only change the hex value as whole (i.e., starting from the B channel).
Knowing the numerical values of the endpoint colors of the transition, you can guess the numerical values of the "transition color" you want. The numerical value of each RGB (red, green, blue) component will be an intermediate value between its endpoints, more or less close to one of the two endpoint values.
The browser is free to interpolate by using the algorithm it prefers. The easiest algorithm moves colors along a straight line in the three-dimensional RGB space. Interpolated colors in this case (called linear interpolation in RGB space) are integer approximations of
R = R[0] * (1 - t) + R[1] * t
G = G[0] * (1 - t) + G[1] * t
B = B[0] * (1 - t) + B[1] * t
for t varying from 0 to 1. For t = 0.5 you get the color which is linearly (in RGB) halfway between the two endpoints. The parameter t may be any function of time (in the simplest case it is a linear function, which means that the color moves at constant speed in RGB space between the two endpoints).
As I said, the browser is free to interpolate in a more complicated way, in order to achieve a better visual result. If you really need to see what the browser does, you can slow it down to snail speed (e.g., by editing the transition-duration with Firebug), then grab the screen (e.g., by pressing the "Print Scrn" key), open your favorite image editor, paste the printed screen (often by pressing Ctrl-V), and finally select a fully colored pixel to get the RGB values of your long craved color.
BTW, your test case is particularly easy, because the endpoints are (0,0,0) and (255,0,0), so that the maroon color you are after is almost certainly nothing but a dark red of the kind (x,0,0). You only have one parameter to vary, you can even do it by trial and error with an editor!

Count number of grid boxes which cover an object in an image

I have displayed grid boxes over an image. I want to count number of grid boxes which cover an object in that image
for example http://snag.gy/geFIZ.jpg. In this image I have displayed grid on image but i need to count how many girds have been taken to cover that object completely.? Kindly help me regarding this
Regards
Dams
Slow, but easy to implement way:
1) Use this topic to add lines to image.
2) Make something like this:
Make a cycle to check every box. In each box check pixels. If you found first white pixel in box, add 1 to number of covering boxes and go for next one.
No code from you - no code from me, sorry :) Good luck!

examine picture through sliding window

I have this image (too large to include) (2351x997) and I'm trying to detect the horizontal lines, first I have to apply a window as
M=T(1:d,1:l);
T is my image, d is width (4 pixels) and l is the length (l=0,2*2351) of my area of interest. Then in this window I have to count black pixels (n), the mean value (m) and standard deviation (σ).
Afterwards if n/(lxd) >0.6 and σ<1,2 I assume I detect a line.
The applied window will slide through image in step of l/4
You can try follow this example,
SCW Example