从node.js中的扫描图像评估复选框

azh*_*har 6 javascript c++ ocr node.js

我想评估复选框是否已从扫描图像中选中.我发现节点模块就像node-dvnode-fv一样.但是什么时候安装它我在mac上遇到以下错误.

../deps/opencv/modules/core/src/arithm1.cpp:444:51: error: constant expression evaluates to 4294967295 which cannot be narrowed to 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 an explicit cast to silence this 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 to 4294967295 which cannot be narrowed to 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 an explicit cast to silence this 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 with exit code: 2
gyp ERR! stack     at 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     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
Run Code Online (Sandbox Code Playgroud)

以上依赖是我的问题的最佳解决方案吗?如果没有,请给我一个很好的解决方案.

aec*_*end 0

抱歉迟来的答复,我昨天和今天都很忙。下面是一个示例,它抓取图像的预定义区域并确定复选框是否已填充或为空。这只是一个起点,可能可以大大改进,但如果扫描的图像质量不错,它应该可以工作。

\n\n

第一步是获取图像的像素。接下来,您可以根据模式抓取图像中包含复选框的区域。最后,通过将图像中该区域的平均亮度与未选中框的基线亮度进行比较来评估该复选框是否被选中。

\n\n

我建议使用get-pixels Node.js 包来获取图像像素。

\n\n

这是一个示例,您可以根据自己的需要进行调整:

\n\n
var get_pixels = require(\xe2\x80\x98get-pixels\xe2\x80\x99);\nvar image_uri = \'path_to_image\';\n\nget_pixels(image_uri, process_image);\n\nvar pattern_width = 800, // Width of your pattern image\n    pattern_height = 1100; // Height of your pattern image\n\n// The pattern image doesn\'t need to be loaded, you just need to use its dimensions to reference the checkbox regions below\n// This is only for scaling purposes in the event that the scanned image is of a higher or lower resolution than what you used as a pattern.\n\nvar checkboxes = [\n    {x1: 10, y1: 10, x2: 30, y2: 30}, // Top left and bottom right corners of the region containing the checkbox\n    {x1: 10, y1: 60, x2: 30, y2: 80}\n];\n\n// You\'ll need to get these by running this on an unchecked form and logging out the adjusted_average of the regions\nvar baseline_average = ??, // The average brightness of an unchecked region\n    darkness_tolerance = ??; // The offset below which the box is still considered unchecked\n\nfunction process_image(err, pixels) {\n\n    if (!err) {\n\n        var regions = get_regions(pixels);\n\n        var checkbox_states = evaluate_regions(regions);\n\n        // Whatever you want to do with the determined states\n\n    }else{\n        console.log(err);\n        return;\n    }\n\n}\n\nfunction get_regions(pixels) {\n\n    var regions = [], // Array to hold the pixel data from selected regions\n        img_width = pixels.shape[0], // Get the width of the image being processed\n        img_height = pixels.shape[1], // Get the height\n        scale_x = img_width / pattern_width, // Get the width scale difference between pattern and image (for different resolution scans)\n        scale_y = img_height / pattern_height; // Get the height scale difference\n\n    for (var i = 0; i < checkboxes.length; i++) {\n\n        var start_x = Math.round(checkboxes[i].x1 * scale_x),\n            start_y = Math.round(checkboxes[i].y1 * scale_y),\n            end_x = Math.round(checkboxes[i].x2 * scale_x),\n            end_y = Math.round(checkboxes[i].y2 * scale_y),\n            region = [];\n\n        for (var y = start_y; y <= end_y; y++) {\n            for (var x = start_x; y <= end_x; x++) {\n                region.push(\n                    pixels.get(x, y, 0), // Red channel\n                    pixels.get(x, y, 1), // Green channel\n                    pixels.get(x, y, 2), // Blue channel\n                    pixels.get(x, y, 3) // Alpha channel\n                );\n            }\n        }\n\n        regions.push(region);\n\n    }\n\n    return regions;\n\n}\n\nfunction evaluate_regions(regions) {\n\n    var states = [];\n\n    for (var i = 0; i < regions.length; i++) {\n\n        var brightest_value = 0,\n            darkest_value = 255,\n            total = 0;\n\n        for (var j = 0; j < regions[i].length; j+=4) {\n\n            var brightness = (regions[i][j] + regions[i][j + 1] + regions[i][j + 2]) / 3; // Pixel brightness\n            if (brightness > brightest_value) brightest_value = brightness;\n            if (brightness < darkest_value) darkest_value = brightness;\n            total += brightness;\n\n        }\n\n        var adjusted_average = (total / (regions[i].length / 4)) - darkest_value; // Adjust contrast\n        var checked = baseline_average - adjusted_average > darkness_tolerance ? true : false;\n\n        states.push(checked);\n\n    }\n\n    return states;\n\n} \n
Run Code Online (Sandbox Code Playgroud)\n