|
Post by brownchoco on Dec 5, 2017 15:44:42 GMT
I am still trying to learn but no luck on finding my desired output. My code: -- ========== Settings ================ Settings:setCompareDimension(true, 960) Settings:setScriptDimension(true, 960) Settings:set("MinSimilarity", 0.65)
-- ========== main program =========== RBar = Region(175, 675, 600, 375) RBar:highlight()
RedTab = Pattern("red.png"):similar(0.8) MixedRed = Pattern("redwithgreen.png"):similar(0.8)
--RTInReg = RBar:findAll(RedTab) --MRInReg = RBar:findAll(MixedRed)
--t = Timer()
for i=1,10 +1 do
wait(0.5)
--curT = tostring(t:check()) --print(curT)
--==== scan image in region ====-- if RBar:exists(RedTab,1) then print("found") end
end ~~ The result always shows "found" 10 times even there is no red color or image in the region. The red.png is a plain red image in 50x50 and the redwithgreen.png is also 50x50 with color green at left side and red at the right. I seen the threads that can help me and try to make this. What is wrong in my code?
|
|
|
Post by zenkrye on Dec 6, 2017 15:04:19 GMT
You have to dig a little since I have not used it but I think you have to check for the color. When Ankulua compares images it uses a grey scale version so no color detection by default.
|
|
|
Post by Mercobots on Dec 6, 2017 15:59:19 GMT
Hi , you will need to know the RGB from green and the image width before aply this code
RBar = Region(175, 675, 600, 375) RBar:highlight()
-- target will be left side (green) local pattern = Pattern("redwithgreen.png"):targetOffset("2 - (image width/2) ", 0)
-- set rgb color from green local green = { r = 0, g = 0, b = 0 }
local match = regionFindAllNoFindException(RBar, pattern)
if #match > 0 then print("Total match = " .. #match) for i, m in ipairs(match) do
-- get left color from match local r, g, b = getColor(m:getTarget())
print("*******************") print("m = " .. i) print("r = " .. r .. " | g = " .. g .. " | b = " .. b)
if r == green.r and g == green.g and b == green.b then m:highlight("redwithgreen") print("id = redwithgreen")
else m:highlight("full red") print("id = full red") end end end
|
|
|
Post by brownchoco on Dec 7, 2017 1:43:05 GMT
Hello, guys. Thanks for the response. I tried running the code given by mecrobot after replacing image width with 50 because the resolution of cropped images are 50x50. This is a simple GIF that can explain about what I wanted to happen. The click will happen to different location of the screen. i.imgur.com/tok9kbe.gifv
|
|
|
Post by Mercobots on Dec 7, 2017 2:05:29 GMT
RBar = Region(175, 675, 600, 375) RBar:highlight()
-- target will be left side (green) local pattern = Pattern("red.png"):targetOffset(-23, 0)
-- set rgb color from green local green = { r = 0, g = 0, b = 0 } local delay_btw_images = 4
while RBar:exists(pattern, delay_btw_images) do
local match = RBar:getLastMatch()
-- get left color from match local r, g, b = getColor(match:getTarget()) match:highlight(0.1)
print("*******************") print("r = " .. r .. " | g = " .. g .. " | b = " .. b)
if r == green.r and g == green.g and b == green.b then toast("click") else toast("Next") end end this one will repeat until it can't find the red image, after img found, he compare the color at left side and if is green will click it set delay_btw_images as you need
|
|
|
Post by brownchoco on Dec 7, 2017 3:14:23 GMT
RBar = Region(175, 675, 600, 375) RBar:highlight()
-- target will be left side (green) local pattern = Pattern("red.png"):targetOffset(-23, 0)
-- set rgb color from green local green = { r = 0, g = 0, b = 0 } local delay_btw_images = 4
while RBar:exists(pattern, delay_btw_images) do
local match = RBar:getLastMatch()
-- get left color from match local r, g, b = getColor(match:getTarget()) match:highlight(0.1)
print("*******************") print("r = " .. r .. " | g = " .. g .. " | b = " .. b)
if r == green.r and g == green.g and b == green.b then toast("click") else toast("Next") end end this one will repeat until it can't find the red image, after img found, he compare the color at left side and if is green will click it set delay_btw_images as you need Thanks for this codes. The output always show "Next" but I will study this codes. However I can see the detection highlight and it is kinda slow. Is it possible to make it detect every 0.5 seconds or lower?
|
|
|
Post by brownchoco on Dec 9, 2017 6:37:01 GMT
Thanks for the help. I learned alot from codes given and taking the steps slowly. Now my script looks like this. -- ========== Settings ================ Settings:setCompareDimension(true, 960) Settings:setScriptDimension(true, 960) Settings:set("MinSimilarity", 0.65) -- ========== main program =========== RBar = Region(425, 220, 170, 40) -- landscape... region of bar RBar:highlight() function searchFunc() --toast("function working") x=470 while(x<=560) do -- while1 local r, g, b = getColor(Location(x, 233)) -- scanning region preview --local SReg = Region(x, 233, 5, 5) --SReg:highlight() -- check if pixel's color is same to assigned RGB if(r==167 and g==115 and b==127) then -- if1 -- stop loop -- check if pixel's color changed every second s=1 clickLoc=Location(850, 480) -- DESIRED CLICK LOCATION while(s<=100) do -- while2 THIS WILL ACT LIKE A TIMER local r2, g2, b2 = getColor(Location(x, 233)) if(r2~=167 and g2~=115 and b2~=127) then -- if2 IF COLOR CHANGED -- go click --print("click") click(clickLoc) searchFunc() break else if(s==100) then -- if3 s=1 end -- END of if3 end -- END of if2 s=s+1 end -- END of while2 break else if(x==550) then -- if4 -- search again x=470 end -- END of if4 end -- END of if1 x=x+15 -- INCREMENT of while1 end -- END of while1 end -- END of function -- print("Process Completed") searchFunc() -- RUN function I'm sorry if my codes looked messy. I use comments for now to avoid confusion until I get used to it. I used while loop in line 31 to act like a timer. I do not know if there is a proper code for this yet. My intention in line 31 is to be a pixel's color checker. I'd like to check the detected pixel per second if it changed it's color... then if it is, it will perform a click in a location. So far, it is working but 30-40% of the time, the click is delayed. I suspect that it is because of the inner while loop in line 31. Any suggestion to make the performance faster and accurate? I am still newbie and sorry if my english is bad.
|
|
|
Post by Exilereven on Dec 9, 2017 22:39:02 GMT
Are you coding from mobile or pc?
|
|
|
Post by brownchoco on Dec 10, 2017 1:12:56 GMT
Are you coding from mobile or pc? From mobile using QLua App.
|
|
|
Post by Exilereven on Dec 10, 2017 3:15:09 GMT
Are you sure your resolution on your mobile is 960?
|
|
|
Post by brownchoco on Dec 11, 2017 1:32:59 GMT
Are you sure your resolution on your mobile is 960? It's 720x1280.
|
|
|
Post by Exilereven on Dec 11, 2017 12:31:31 GMT
Then if your script runs in portrait mode (long ways up and down)
Your resolution shoukd be 720, so it knows the width.
Alternatively, if your in landscape mode (long way is sideways.
Your resolution would be set to 1280, so thst again it know your width.
Make sure you got settings done up right, before we continue.
|
|
|
Post by Mercobots on Dec 11, 2017 13:33:40 GMT
ok sorry for late reply in this example i added color function, it will help you a lot to detect the color, so how it works? look at the image and set properly "color_search_timer" - timeout until green is over red img "onlyRed.png" - crop a new image only with the red square "redColor -> color" - set RGB red color "click("desired Location")" - click location once done the code will search for the image, once found will look at red color until timeout or green pass over it. If timeout he will search for a new image, if color red pass over will click at the desired location -- color functionc -- ======================================== function colorExists(obj, time) time = time or 1 local timer = Timer() local r, g, b -- while in time while true do r, g, b = getColor(obj.location)
if obj.diff then if math.abs(obj.color[1] - r) <= obj.diff[1] then if math.abs(obj.color[2] - g) <= obj.diff[2] then if math.abs(obj.color[3] - b) <= obj.diff[3] then return true end end end else if r == obj.color[1] and g == obj.color[2] and b == obj.color[3] then return true end end
-- r, g, b = nil, nil, nil
if timer:check() > time then return false end end end
-- ======================================== RBar = Region(175, 675, 600, 375) RBar:highlight()
-- ======================================== local function searchMyColor() -- color obj local redColor = { color = { 167, 115, 127 }, -- red RGB diff = { 10, 10, 10 }, -- Diff red RGB }
-- color timer local timer = Timer() local color_search_timer = 30
-- only look at the image for 1 sec if RBar:exists("onlyRed.png", 1) then
-- get location color if image found redColor.location = RBar:getLastMatch():getTarget()
-- while color search while true do
-- seach next image if color timeout if timer:check() > color_search_timer then break end
-- since is in time and color red is NOT visible then click if not colorExists(redColor, 0) then click("desired Location") return true end end end
toast("next search") return false end
-- infinite loop -- ======================================== while true do searchMyColor() end
|
|
|
Post by Exilereven on Dec 11, 2017 17:11:36 GMT
Are you coding from mobile or pc? From mobile using QLua App. I wish someone would come out with an ide like intellij but for android, so we can use forrusco syntax stuff he made for it but on android lol. I still have not come across anything for mobile users only, I just have to keep track of all my syntax matching and crap myself.
|
|
|
Post by brownchoco on Dec 14, 2017 10:12:09 GMT
ok sorry for late reply in this example i added color function, it will help you a lot to detect the color, so how it works? look at the image and set properly "color_search_timer" - timeout until green is over red img "onlyRed.png" - crop a new image only with the red square "redColor -> color" - set RGB red color "click("desired Location")" - click location once done the code will search for the image, once found will look at red color until timeout or green pass over it. If timeout he will search for a new image, if color red pass over will click at the desired location -- color functionc -- ======================================== function colorExists(obj, time) time = time or 1 local timer = Timer() local r, g, b -- while in time while true do r, g, b = getColor(obj.location)
if obj.diff then if math.abs(obj.color[1] - r) <= obj.diff[1] then if math.abs(obj.color[2] - g) <= obj.diff[2] then if math.abs(obj.color[3] - b) <= obj.diff[3] then return true end end end else if r == obj.color[1] and g == obj.color[2] and b == obj.color[3] then return true end end
-- r, g, b = nil, nil, nil
if timer:check() > time then return false end end end
-- ======================================== RBar = Region(175, 675, 600, 375) RBar:highlight()
-- ======================================== local function searchMyColor() -- color obj local redColor = { color = { 167, 115, 127 }, -- red RGB diff = { 10, 10, 10 }, -- Diff red RGB }
-- color timer local timer = Timer() local color_search_timer = 30
-- only look at the image for 1 sec if RBar:exists("onlyRed.png", 1) then
-- get location color if image found redColor.location = RBar:getLastMatch():getTarget()
-- while color search while true do
-- seach next image if color timeout if timer:check() > color_search_timer then break end
-- since is in time and color red is NOT visible then click if not colorExists(redColor, 0) then click("desired Location") return true end end end
toast("next search") return false end
-- infinite loop -- ======================================== while true do searchMyColor() end
Thank you. This help me learn more and improve.
|
|