|
Post by jblade on Apr 10, 2018 9:56:16 GMT
- A pic from each word attack, defense... - A function to calculate each OCR region depending the pic word - A function to validate the OCR numbers
These three are done. The code can get the data from the picture but still cannot read '%'. What should I do for identifying percentage?
|
|
|
Post by Mercobots on Apr 10, 2018 10:13:38 GMT
- A pic from each word attack, defense... - A function to calculate each OCR region depending the pic word - A function to validate the OCR numbers These three are done. The code can get the data from the picture but still cannot read '%'. What should I do for identifying percentage? now crop a new image only with "%" and create a function like this getNumberType()I changed getOCRRegion() because you need to reuse it, now it will nly return the OCR region to get the value use this getOCRNumber() getNumberType() uses a similarity of 0.8(80%) if the script fails on detecting the image, lower this value to 0.75 the whole code Be aware i don't test the code and maybe there is a better approach to do it -- Function to calculate OCR region -- ---------------------------------- function getOCRRegion(match) if match then -- save image location and size local img = { x = match:getX(), y = match:getY(), w = match:getW(), h = match:getH(), }
-- SET OCR REGION local ocr_r = Region(img.x + img.w, img.y, 100, img.h)
-- DEBUG toast('img') match:highlight(2) -- toast('ocr region') ocr_r:highlight(2) -- END DEBUG return ocr_r end end
-- ---------------------------------- function getOCRNumber(ocr_r) if ocr_r then local val, ocr_result = numberOCRNoFindException(ocr_r, "num_")
if ocr_result and val < 9999 then return val end end return false end
-- ---------------------------------- function getNumberType(ocr_r) if ocr_r:exists(Pattern('percetage.png'):similar(0.8)) then return '_percentage_' end
return '_flat_' end
-- start -- ---------------------------------- if exists('attack.png') then local match = getLastMatch() local ocr_region = getOCRRegion(match)
print('---------------') print('Img = attack') print('Value = ' .. getOCRNumber(ocr_region)) print('type = ' .. getNumberType(ocr_region)) end
|
|
|
Post by jblade on Apr 10, 2018 10:24:10 GMT
Thank you, I will try
|
|
|
Post by jblade on Apr 10, 2018 10:48:04 GMT
nice code, it works~ Are there any way to set all "img.png" in a list or array (like that: subProperty = {"subAttack.png","subDefense.png","subHP.png","subRecovery.png","subResist.png"})then when the program check the gem's sub-properties I only need to count how many times it match the elements in the list.
|
|
|
Post by Mercobots on Apr 10, 2018 10:55:34 GMT
nice code, it works~ Are there any way to set all "img.png" in a list or array (like that: subProperty = {"subAttack.png","subDefense.png","subHP.png","subRecovery.png","subResist.png"})then when the program check the gem's sub-properties I only need to count how many times it match the elements in the list. somthing like this ? targets = { 'attack', 'defense', }
for i, name in ipairs(targets) do toast(name)
if exists(name .. '.png') then local match = getLastMatch() local ocr_region = getOCRRegion(match)
print('---------------') print('Img = ' .. name) print('Value = ' .. getOCRNumber(ocr_region)) print('type = ' .. getNumberType(ocr_region)) end end
|
|
|
Post by jblade on Apr 10, 2018 11:03:06 GMT
looks like the code is what I exactly need. I will try it. Thank you very much
|
|