Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

56
LINES

< > BotCompany Repo | #336 // Horizontal split

Lua code - Image recognition

function rgb(i)
  local r = bit32.band(bit32.rshift(i, 16), 255)
    local g = bit32.band(bit32.rshift(i, 8), 255)
    local b = bit32.band(i, 255)
  return r, g, b
end

function bright(r, g, b)
  return (r+g+b)/(255*3)
end

function map(list, f)
  local tbl2 = {}
  for _, x in ipairs(list) do
    table.insert(tbl2, f(x))
  end
  return tbl2
end

function segment2string(s)
  local x1, x2 = unpack(s)
  return x1.."-"..x2
end

w, h = img.width, img.height
brightnessThreshold = 0.9

function isEmpty(x)
  for y=0, h-1 do
    if bright(rgb(img.getInt(x, y))) <= brightnessThreshold then
      return false
    end
  end
  return true
end

lastEmpty = true
segments = {}

for x=0, w-1 do
  empty = isEmpty(x)
  if empty and not lastEmpty then
    table.insert(segments, {start, x})
  elseif not empty and lastEmpty then
    start = x
  end
  lastEmpty = empty
end

if not lastEmpty then
  table.insert(segments, {start, w})
end

if #segments >= 2 then -- don't bother with only 1 segment
  return "Horizontal segments: "..table.concat(map(segments, segment2string), ", ")
end

download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Image recognition results

show nils
Image Result Result calculated
#1000184 Horizontal segments: 0-6, 8-13, 15-21, 23-29, 31-37, 39-45, 47-48 2016-08-08 09:19:45
Lua instructions: 15k (36 ms)

[raw result]
[visualize]
#1000180 Horizontal segments: 0-12, 13-54, 55-68, 69-81, 82-103, 104-138, 139-145, 146-172, 173-179, 181-187,... 2016-08-08 02:00:25
Lua instructions: 789k (89 ms)

[raw result]
[visualize]
#1004090 java.lang.OutOfMemoryError: Java heap space 2016-08-07 13:34:13

[raw result]
[visualize]
#1000336 javax.imageio.IIOException: Can't get input stream from URL! 2016-08-07 05:02:57

[raw result]
[visualize]
#1004060 java.lang.OutOfMemoryError: Java heap space 2016-08-05 13:07:21

[raw result]
[visualize]
#1000153 Horizontal segments: 24-25, 30-32, 38-43, 45-50, 51-58, 59-64, 65-72, 73-79, 80-85, 89-92, 95-98, 10... 2016-08-03 05:33:52
Lua instructions: 1576k (272 ms)

[raw result]
[visualize]
#1000015 Horizontal segments: 6-12, 13-19, 20-32, 34-40, 41-47, 55-61, 62-68, 69-75, 76-82, 90-95, 97-102, 10... 2016-08-02 17:05:02
Lua instructions: 100k (79 ms)

[raw result]
[visualize]
#1000332 Horizontal segments: 35-221, 257-446 2016-08-02 10:08:20
Lua instructions: 2454k (280 ms)

[raw result]
[visualize]
#1000331 Horizontal segments: 48-313, 316-323, 324-327, 328-329, 330-333, 339-341 2016-08-01 17:37:51
Lua instructions: 1214k (135 ms)

[raw result]
[visualize]
#1000330 java.lang.OutOfMemoryError: Java heap space 2016-08-01 17:36:29

[raw result]
[visualize]
#1000326 java.lang.OutOfMemoryError: Java heap space 2016-08-01 16:53:22

[raw result]
[visualize]
#1000314 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 14:43:28

[raw result]
[visualize]
#1000312 java.lang.OutOfMemoryError: Java heap space 2016-08-01 14:21:30

[raw result]
[visualize]
#1000309 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 14:20:52

[raw result]
[visualize]
#1000301 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 14:20:50

[raw result]
[visualize]
#1000283 Horizontal segments: 8-193, 207-393 2016-08-01 13:50:57
Lua instructions: 585k (145 ms)

[raw result]
[visualize]
#1000241 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 09:35:20

[raw result]
[visualize]
#499 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 08:34:29

[raw result]
[visualize]
#500 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 08:34:29

[raw result]
[visualize]
#1000206 Horizontal segments: 236-509, 582-699, 716-848, 874-984, 1004-1136, 1166-1364 2016-08-01 07:54:30
Lua instructions: 73725k (8470 ms)

[raw result]
[visualize]
#488 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 07:29:04

[raw result]
[visualize]
#1000218 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 05:08:29

[raw result]
[visualize]
#1000212 java.lang.OutOfMemoryError: Java heap space 2016-08-01 05:08:29

[raw result]
[visualize]
#1000196 java.lang.OutOfMemoryError: Java heap space 2016-08-01 04:40:52

[raw result]
[visualize]
#1000185 Horizontal segments: 0-7, 9-26, 27-31, 33-38, 40-46, 47-48 2016-08-01 03:04:14
Lua instructions: 14k (17 ms)

[raw result]
[visualize]
#1000183 Horizontal segments: 0-6, 8-14, 16-21, 22-26, 28-29, 31-37, 39-45 2016-08-01 02:54:46
Lua instructions: 16k (35 ms)

[raw result]
[visualize]
#1000182 Horizontal segments: 0-6, 8-13, 15-21, 23-29, 31-35, 36-42, 44-50, 51-55, 57-63 2016-08-01 02:54:43
Lua instructions: 17k (37 ms)

[raw result]
[visualize]
#1000181 Horizontal segments: 0-7, 9-15, 17-23, 24-28, 30-35, 37-42, 44-50 2016-08-01 02:54:26
Lua instructions: 15k (67 ms)

[raw result]
[visualize]
#1000171 Horizontal segments: 0-40, 42-62, 64-87, 101-127, 128-152, 153-196, 212-238, 240-247, 251-273, 275-2... 2016-08-01 01:48:41
Lua instructions: 471k (147 ms)

[raw result]
[visualize]
#1000163 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-08-01 00:53:36

[raw result]
[visualize]
#1000162 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 23:21:19

[raw result]
[visualize]
#1000155 Horizontal segments: 24-25, 30-37, 38-65, 66-72, 73-79, 81-84, 88-91, 94-99, 100-107, 109-112, 116-1... 2016-07-31 22:34:19
Lua instructions: 1376k (238 ms)

[raw result]
[visualize]
#1000151 Horizontal segments: 24-25, 40-41, 46-47, 48-49, 51-58, 59-64, 65-72, 73-79, 82-83, 89-92, 95-98, 10... 2016-07-31 22:34:19
Lua instructions: 1610k (267 ms)

[raw result]
[visualize]
#1000148 Horizontal segments: 1-13, 22-23, 29-35, 36-42, 43-56, 57-70, 71-77, 78-84, 85-97, 99-105, 106-112, ... 2016-07-31 22:16:28
Lua instructions: 1562k (254 ms)

[raw result]
[visualize]
#1000114 java.lang.OutOfMemoryError: Java heap space 2016-07-31 19:52:13

[raw result]
[visualize]
#1000100 Horizontal segments: 13-214, 215-227, 230-232, 233-239, 242-259 2016-07-31 19:46:32
Lua instructions: 588k (155 ms)

[raw result]
[visualize]
#1000099 Horizontal segments: 0-34, 35-54, 55-58 2016-07-31 19:46:17
Lua instructions: 18k (4 ms)

[raw result]
[visualize]
#362 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:45:39

[raw result]
[visualize]
#1000086 Horizontal segments: 24-50, 53-73, 76-97, 101-123, 128-146, 150-167, 168-191, 195-216, 222-227, 230-... 2016-07-31 19:44:43
Lua instructions: 977k (188 ms)

[raw result]
[visualize]
#1000085 Horizontal segments: 20-46, 51-75, 80-106, 109-134, 136-151, 154-180, 184-208, 213-238, 243-269, 272... 2016-07-31 19:44:41
Lua instructions: 776k (179 ms)

[raw result]
[visualize]
#1000084 Horizontal segments: 22-48, 53-77, 82-107, 111-137, 140-167, 171-197, 200-226, 230-255, 260-286, 289... 2016-07-31 19:44:34
Lua instructions: 550k (71 ms)

[raw result]
[visualize]
#1000083 Horizontal segments: 20-47, 50-73, 77-106, 107-131, 134-157, 163-186, 190-214, 228-252, 256-261, 266... 2016-07-31 19:44:27
Lua instructions: 481k (224 ms)

[raw result]
[visualize]
#1000082 Horizontal segments: 36-72, 75-106, 114-146, 160-196, 200-231, 236-273, 277-308, 312-343, 351-381, 3... 2016-07-31 19:44:21
Lua instructions: 1928k (223 ms)

[raw result]
[visualize]
#1000081 Horizontal segments: 22-53, 57-63, 73-104, 108-141, 147-176, 182-214, 217-253, 256-262, 271-302, 323... 2016-07-31 19:43:55
Lua instructions: 1243k (219 ms)

[raw result]
[visualize]
#1000080 Horizontal segments: 20-47, 50-72, 74-101, 105-130, 134-157, 161-181, 183-211, 216-239, 245-250, 253... 2016-07-31 19:43:52
Lua instructions: 1253k (227 ms)

[raw result]
[visualize]
#1000079 Horizontal segments: 16-319, 322-341, 343-380, 382-411, 414-459, 462-499, 501-536, 539-566, 569-605,... 2016-07-31 19:43:50
Lua instructions: 1077k (205 ms)

[raw result]
[visualize]
#1000078 Horizontal segments: 6-43, 47-82, 98-134, 136-165, 169-198, 201-230, 235-270 2016-07-31 19:43:43
Lua instructions: 291k (189 ms)

[raw result]
[visualize]
#201 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#183 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#182 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#178 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#145 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#141 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#115 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#113 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#100 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#98 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#93 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#92 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#91 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#90 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#85 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#84 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#49 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#48 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:42

[raw result]
[visualize]
#1000014 Horizontal segments: 1-7, 9-14, 16-20, 21-27, 29-35, 37-43, 45-50, 52-58, 60-66, 67-71, 73-79, 81-87... 2016-07-31 19:43:41
Lua instructions: 78k (68 ms)

[raw result]
[visualize]
#1000026 Horizontal segments: 3-618, 624-920 2016-07-31 19:43:40
Lua instructions: 2321k (258 ms)

[raw result]
[visualize]
#1000041 Horizontal segments: 52-250, 254-256 2016-07-31 19:43:39
Lua instructions: 2738k (417 ms)

[raw result]
[visualize]
#1000077 Horizontal segments: 12-30, 32-49, 50-81, 86-117, 119-136 2016-07-31 19:43:37
Lua instructions: 133k (87 ms)

[raw result]
[visualize]
#1000054 Horizontal segments: 8-21, 22-65 2016-07-31 19:43:37
Lua instructions: 1231k (212 ms)

[raw result]
[visualize]
#1000053 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:37

[raw result]
[visualize]
#309 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 19:43:37

[raw result]
[visualize]
#1000219 java.lang.OutOfMemoryError: Java heap space 2016-07-31 18:51:37

[raw result]
[visualize]
#1003745 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 18:51:23

[raw result]
[visualize]
#489 java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operat... 2016-07-31 18:51:22

[raw result]
[visualize]
#1000310 javax.imageio.IIOException: Can't get input stream from URL! 2015-07-13 08:30:01

[raw result]
[visualize]

Snippet ID: #336
Snippet name: Horizontal split
Eternal ID of this version: #336/1
Text MD5: b2a3270b7c117a924fd85cf3a92513f1
Author: stefan
Category:
Type: Lua code - Image recognition
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-01-24 18:36:14
Source code size: 1130 bytes / 56 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1852 / 264
Referenced in: [show references]