I am working on an app to detect "damage amount" of paper money.
The app will assess the user's input image, and confirm if they have rights to a replacement note.
The output is : if 30% of lost of money object, can allow changing at the bank
.
I have idea, we make capture with camera of money and the damage background is white so, in AS3 can count how percent of white color. If less then 30% so is good to change on the Bank.
Any idea (calculation) of how to count percentage of white colour in image?. Thanks.
-- EDIT --
i have the code @VC.One, may you make correction? Thanks.
import flash.media.Camera; import flash.media.Video; import flash.display.BitmapData; import flash.display.Bitmap; import flash.display.Sprite; import flash.events.MouseEvent; import flash.text.TextField; var camMoney: Camera = Camera.getCamera(); camMoney.setQuality(0, 100); camMoney.setMode(480, 300, 30, true); var vidMoney: Video = new Video(480, 300) vidMoney.x = 0; vidMoney.y = 10; addChild(vidMoney); vidMoney.attachCamera(camMoney); var moneyBD: BitmapData = new BitmapData(vidMoney.width, vidMoney.height); var moneyBM: Bitmap = new Bitmap(moneyBD); moneyBM.x = 0; moneyBM.y = 376; addChild(moneyBM); var circle: Sprite = new Sprite(); circle.graphics.lineStyle(2, 0xFFFFFF); circle.graphics.beginFill(0x000000); circle.graphics.drawCircle(225, 340, 20); circle.graphics.endFill(); addChild(circle); circle.buttonMode = true; circle.addEventListener(MouseEvent.CLICK, capture); function capture(e: MouseEvent): void { moneyBD.draw(vidMoney); } var circleRect: Sprite = new Sprite(); circleRect.graphics.lineStyle(2, 0xFFFFFF); circleRect.graphics.beginFill(0xFF0000); circleRect.graphics.drawRoundRect(260, 320, 60, 40, 30); circleRect.graphics.endFill(); addChild(circleRect); circleRect.buttonMode = true; circleRect.addEventListener(MouseEvent.CLICK, analisa); function analisa(e: MouseEvent): void { var xi: int; var yi: int; var pixel: uint; var color: uint; var pointsWhite: Array = []; for (xi = 0; xi = 2) { var lengthOfWhiteSpace: int = pointGroup[pointGroup.length - 1].x - pointGroup[0].x; var t: TextField = new TextField(); t.x = pointGroup[0].x; t.y = pointGroup[0].y; addChild(t); } }
histogram
or even just usegetPixel
(which tells you colour from a tested pixel position). Use aFor
loop to scan each pixel and test if it matches white (0xFFFFF
) so logic like this :if white == myBMPdata.getPixel( i, j ) then { so add +1 to totalWhitePixels };
. When the scan is finished compare your total image pixels vs total white pixels, use math to calculate percentage. – VC.One