javascript - Evaluate check box from a scanned image in node.js -


i want evaluate checkbox checked or not scanned image. found node module node-dv , node-fv this. when install got following error on mac.

../deps/opencv/modules/core/src/arithm1.cpp:444:51: error: constant expression evaluates 4294967295 cannot narrowed type 'int' [-wc++11-narrowing] static int cv_decl_aligned(16) v64f_absmask[] = { 0xffffffff, 0x7fffffff, 0xffffffff, 0x7fffffff };                                                   ^~~~~~~~~~ ../deps/opencv/modules/core/src/arithm1.cpp:444:51: note: insert explicit cast silence issue static int cv_decl_aligned(16) v64f_absmask[] = { 0xffffffff, 0x7fffffff, 0xffffffff, 0x7fffffff };                                                   ^~~~~~~~~~                                                   static_cast<int>( ) ../deps/opencv/modules/core/src/arithm1.cpp:444:75: error: constant expression evaluates 4294967295 cannot narrowed type 'int' [-wc++11-narrowing] static int cv_decl_aligned(16) v64f_absmask[] = { 0xffffffff, 0x7fffffff, 0xffffffff, 0x7fffffff };                                                                           ^~~~~~~~~~ ../deps/opencv/modules/core/src/arithm1.cpp:444:75: note: insert explicit cast silence issue static int cv_decl_aligned(16) v64f_absmask[] = { 0xffffffff, 0x7fffffff, 0xffffffff, 0x7fffffff };                                                                           ^~~~~~~~~~                                                                           static_cast<int>( ) 2 errors generated. make: *** [release/obj.target/libopencv/deps/opencv/modules/core/src/arithm1.o] error 1 gyp err! build error  gyp err! stack error: `make` failed exit code: 2 gyp err! stack     @ childprocess.onexit (/users/entapzian/.nvm/versions/node/v4.3.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23) gyp err! stack     @ emittwo (events.js:87:13) gyp err! stack     @ childprocess.emit (events.js:172:7) gyp err! stack     @ process.childprocess._handle.onexit (internal/child_process.js:200:12) 

is above dependency best solution problem? if not please suggest me solution.

sorry delayed answer, i've been busy yesterday , today. here example grabs predefined regions of image , determines if checkboxes filled or empty. starting point, , can improved, should work if scanned image of decent quality.

the first step getting image's pixels. next, regions in image contain checkboxes grabbing them according pattern. last, evaluate whether or not checkbox checked comparing average brightness of region in image baseline brightness of unchecked box.

i recommend using get-pixels node.js package image pixels.

here's example can adjust suit needs:

var get_pixels = require(‘get-pixels’); var image_uri = 'path_to_image';  get_pixels(image_uri, process_image);  var pattern_width = 800, // width of pattern image     pattern_height = 1100; // height of pattern image  // pattern image doesn't need loaded, need use dimensions reference checkbox regions below // scaling purposes in event scanned image of higher or lower resolution used pattern.  var checkboxes = [     {x1: 10, y1: 10, x2: 30, y2: 30}, // top left , bottom right corners of region containing checkbox     {x1: 10, y1: 60, x2: 30, y2: 80} ];  // you'll need these running on unchecked form , logging out adjusted_average of regions var baseline_average = ??, // average brightness of unchecked region     darkness_tolerance = ??; // offset below box still considered unchecked  function process_image(err, pixels) {      if (!err) {          var regions = get_regions(pixels);          var checkbox_states = evaluate_regions(regions);          // whatever want determined states      }else{         console.log(err);         return;     }  }  function get_regions(pixels) {      var regions = [], // array hold pixel data selected regions         img_width = pixels.shape[0], // width of image being processed         img_height = pixels.shape[1], // height         scale_x = img_width / pattern_width, // width scale difference between pattern , image (for different resolution scans)         scale_y = img_height / pattern_height; // height scale difference      (var = 0; < checkboxes.length; i++) {          var start_x = math.round(checkboxes[i].x1 * scale_x),             start_y = math.round(checkboxes[i].y1 * scale_y),             end_x = math.round(checkboxes[i].x2 * scale_x),             end_y = math.round(checkboxes[i].y2 * scale_y),             region = [];          (var y = start_y; y <= end_y; y++) {             (var x = start_x; y <= end_x; x++) {                 region.push(                     pixels.get(x, y, 0), // red channel                     pixels.get(x, y, 1), // green channel                     pixels.get(x, y, 2), // blue channel                     pixels.get(x, y, 3) // alpha channel                 );             }         }          regions.push(region);      }      return regions;  }  function evaluate_regions(regions) {      var states = [];      (var = 0; < regions.length; i++) {          var brightest_value = 0,             darkest_value = 255,             total = 0;          (var j = 0; j < regions[i].length; j+=4) {              var brightness = (regions[i][j] + regions[i][j + 1] + regions[i][j + 2]) / 3; // pixel brightness             if (brightness > brightest_value) brightest_value = brightness;             if (brightness < darkest_value) darkest_value = brightness;             total += brightness;          }          var adjusted_average = (total / (regions[i].length / 4)) - darkest_value; // adjust contrast         var checked = baseline_average - adjusted_average > darkness_tolerance ? true : false;          states.push(checked);      }      return states;  }  

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -