BVB Source Codes

jsfeat Show jsfeat_struct.js Source code

Return Download jsfeat: download jsfeat_struct.js Source code - Download jsfeat Source code - Type:.js
  1. /**
  2.  * @author Eugene Zatepyakin / http://inspirit.ru/
  3.  */
  4.  
  5. (function(global) {
  6.     "use strict";
  7.     //
  8.  
  9.     // CONSTANTS
  10.     var EPSILON = 0.0000001192092896;
  11.     var FLT_MIN = 1E-37;
  12.  
  13.     // implementation from CCV project
  14.     // currently working only with u8,s32,f32
  15.     var U8_t = 0x0100,
  16.         S32_t = 0x0200,
  17.         F32_t = 0x0400,
  18.         S64_t = 0x0800,
  19.         F64_t = 0x1000;
  20.  
  21.     var C1_t = 0x01,
  22.         C2_t = 0x02,
  23.         C3_t = 0x03,
  24.         C4_t = 0x04;
  25.  
  26.     var _data_type_size = new Int32Array([ -1, 1, 4, -1, 4, -1, -1, -1, 8, -1, -1, -1, -1, -1, -1, -1, 8 ]);
  27.  
  28.     var get_data_type = (function () {
  29.         return function(type) {
  30.             return (type & 0xFF00);
  31.         }
  32.     })();
  33.  
  34.     var get_channel = (function () {
  35.         return function(type) {
  36.             return (type & 0xFF);
  37.         }
  38.     })();
  39.  
  40.     var get_data_type_size = (function () {
  41.         return function(type) {
  42.             return _data_type_size[(type & 0xFF00) >> 8];
  43.         }
  44.     })();
  45.  
  46.     // color conversion
  47.     var COLOR_RGBA2GRAY = 0;
  48.     var COLOR_RGB2GRAY = 1;
  49.     var COLOR_BGRA2GRAY = 2;
  50.     var COLOR_BGR2GRAY = 3;
  51.  
  52.     // box blur option
  53.     var BOX_BLUR_NOSCALE = 0x01;
  54.     // svd options
  55.     var SVD_U_T = 0x01;
  56.     var SVD_V_T = 0x02;
  57.  
  58.     var data_t = (function () {
  59.         function data_t(size_in_bytes, buffer) {
  60.             // we need align size to multiple of 8
  61.             this.size = ((size_in_bytes + 7) | 0) & -8;
  62.             if (typeof buffer === "undefined") {
  63.                 this.buffer = new ArrayBuffer(this.size);
  64.             } else {
  65.                 this.buffer = buffer;
  66.                 this.size = buffer.length;
  67.             }
  68.             this.u8 = new Uint8Array(this.buffer);
  69.             this.i32 = new Int32Array(this.buffer);
  70.             this.f32 = new Float32Array(this.buffer);
  71.             this.f64 = new Float64Array(this.buffer);
  72.         }
  73.         return data_t;
  74.     })();
  75.  
  76.     var matrix_t = (function () {
  77.         // columns, rows, data_type
  78.         function matrix_t(c, r, data_type, data_buffer) {
  79.             this.type = get_data_type(data_type)|0;
  80.             this.channel = get_channel(data_type)|0;
  81.             this.cols = c|0;
  82.             this.rows = r|0;
  83.             if (typeof data_buffer === "undefined") {
  84.                 this.allocate();
  85.             } else {
  86.                 this.buffer = data_buffer;
  87.                 // data user asked for
  88.                 this.data = this.type&U8_t ? this.buffer.u8 : (this.type&S32_t ? this.buffer.i32 : (this.type&F32_t ? this.buffer.f32 : this.buffer.f64));
  89.             }
  90.         }
  91.         matrix_t.prototype.allocate = function() {
  92.             // clear references
  93.             delete this.data;
  94.             delete this.buffer;
  95.             //
  96.             this.buffer = new data_t((this.cols * get_data_type_size(this.type) * this.channel) * this.rows);
  97.             this.data = this.type&U8_t ? this.buffer.u8 : (this.type&S32_t ? this.buffer.i32 : (this.type&F32_t ? this.buffer.f32 : this.buffer.f64));
  98.         }
  99.         matrix_t.prototype.copy_to = function(other) {
  100.             var od = other.data, td = this.data;
  101.             var i = 0, n = (this.cols*this.rows*this.channel)|0;
  102.             for(; i < n-4; i+=4) {
  103.                 od[i] = td[i];
  104.                 od[i+1] = td[i+1];
  105.                 od[i+2] = td[i+2];
  106.                 od[i+3] = td[i+3];
  107.             }
  108.             for(; i < n; ++i) {
  109.                 od[i] = td[i];
  110.             }
  111.         }
  112.         matrix_t.prototype.resize = function(c, r, ch) {
  113.             if (typeof ch === "undefined") { ch = this.channel; }
  114.             // relocate buffer only if new size doesnt fit
  115.             var new_size = (c * get_data_type_size(this.type) * ch) * r;
  116.             if(new_size > this.buffer.size) {
  117.                 this.cols = c;
  118.                 this.rows = r;
  119.                 this.channel = ch;
  120.                 this.allocate();
  121.             } else {
  122.                 this.cols = c;
  123.                 this.rows = r;
  124.                 this.channel = ch;
  125.             }
  126.         }
  127.  
  128.         return matrix_t;
  129.     })();
  130.  
  131.     var pyramid_t = (function () {
  132.  
  133.         function pyramid_t(levels) {
  134.             this.levels = levels|0;
  135.             this.data = new Array(levels);
  136.             this.pyrdown = jsfeat.imgproc.pyrdown;
  137.         }
  138.  
  139.         pyramid_t.prototype.allocate = function(start_w, start_h, data_type) {
  140.             var i = this.levels;
  141.             while(--i >= 0) {
  142.                 this.data[i] = new matrix_t(start_w >> i, start_h >> i, data_type);
  143.             }
  144.         }
  145.  
  146.         pyramid_t.prototype.build = function(input, skip_first_level) {
  147.             if (typeof skip_first_level === "undefined") { skip_first_level = true; }
  148.             // just copy data to first level
  149.             var i = 2, a = input, b = this.data[0];
  150.             if(!skip_first_level) {
  151.                 var j=input.cols*input.rows;
  152.                 while(--j >= 0) {
  153.                     b.data[j] = input.data[j];
  154.                 }
  155.             }
  156.             b = this.data[1];
  157.             this.pyrdown(a, b);
  158.             for(; i < this.levels; ++i) {
  159.                 a = b;
  160.                 b = this.data[i];
  161.                 this.pyrdown(a, b);
  162.             }
  163.         }
  164.  
  165.         return pyramid_t;
  166.     })();
  167.  
  168.     var keypoint_t = (function () {
  169.         function keypoint_t(x,y,score,level,angle) {
  170.             if (typeof x === "undefined") { x=0; }
  171.             if (typeof y === "undefined") { y=0; }
  172.             if (typeof score === "undefined") { score=0; }
  173.             if (typeof level === "undefined") { level=0; }
  174.             if (typeof angle === "undefined") { angle=-1.0; }
  175.  
  176.             this.x = x;
  177.             this.y = y;
  178.             this.score = score;
  179.             this.level = level;
  180.             this.angle = angle;
  181.         }
  182.         return keypoint_t;
  183.     })();
  184.  
  185.  
  186.     // data types
  187.     global.U8_t = U8_t;
  188.     global.S32_t = S32_t;
  189.     global.F32_t = F32_t;
  190.     global.S64_t = S64_t;
  191.     global.F64_t = F64_t;
  192.     // data channels
  193.     global.C1_t = C1_t;
  194.     global.C2_t = C2_t;
  195.     global.C3_t = C3_t;
  196.     global.C4_t = C4_t;
  197.  
  198.     // popular formats
  199.     global.U8C1_t = U8_t | C1_t;
  200.     global.U8C3_t = U8_t | C3_t;
  201.     global.U8C4_t = U8_t | C4_t;
  202.  
  203.     global.F32C1_t = F32_t | C1_t;
  204.     global.F32C2_t = F32_t | C2_t;
  205.     global.S32C1_t = S32_t | C1_t;
  206.     global.S32C2_t = S32_t | C2_t;
  207.  
  208.     // constants
  209.     global.EPSILON = EPSILON;
  210.     global.FLT_MIN = FLT_MIN;
  211.  
  212.     // color convert
  213.     global.COLOR_RGBA2GRAY = COLOR_RGBA2GRAY;
  214.     global.COLOR_RGB2GRAY = COLOR_RGB2GRAY;
  215.     global.COLOR_BGRA2GRAY = COLOR_BGRA2GRAY;
  216.     global.COLOR_BGR2GRAY = COLOR_BGR2GRAY;
  217.  
  218.     // options
  219.     global.BOX_BLUR_NOSCALE = BOX_BLUR_NOSCALE;
  220.     global.SVD_U_T = SVD_U_T;
  221.     global.SVD_V_T = SVD_V_T;
  222.  
  223.     global.get_data_type = get_data_type;
  224.     global.get_channel = get_channel;
  225.     global.get_data_type_size = get_data_type_size;
  226.  
  227.     global.data_t = data_t;
  228.     global.matrix_t = matrix_t;
  229.     global.pyramid_t = pyramid_t;
  230.     global.keypoint_t = keypoint_t;
  231.  
  232. })(jsfeat);
  233.  
downloadjsfeat_struct.js Source code - Download jsfeat Source code
Related Source Codes/Software:
flakes - Flakes is an Admin Template Framework. A combinati... 2017-04-15
capstone - Capstone disassembly/disassembler framework: Core ... 2017-04-15
nginx-resources - A collection of resources covering Nginx, Nginx + ... 2017-04-15
utron - A lightweight MVC framework for Go(Golang) 2017-04-15
cfssl - CFSSL: Cloudflare's PKI and TLS toolkit ... 2017-04-15
MLeaksFinder - Find memory leaks in your iOS app at develop time. 2017-04-16
qt - Qt binding for Go (Golang) which supports Windows ... 2017-04-16
rainloop-webmail - Simple, modern & fast web-based email client ... 2017-04-16
pencil - Multiplatform GUI Prototyping/Wireframing 2017-04-16
x64dbg - An open-source x64/x32 debugger for windows. ... 2017-04-16
Toucan - Fabulous Image Processing in Swift 2017-04-23
CoffeeScriptRedux - 2017-04-23
breakpoint - Really simple media queries in Sa 2017-04-23
libsvm - 2017-04-22
grr - GRR Rapid Response: remote live forensics for inci... 2017-04-22
grit - **Grit is no longer maintained. Check out libgit2/... 2017-04-22
guard-livereload - Guard::LiveReload automatically reload your browse... 2017-04-22
Begin-Latex-in-minutes - Brief Intro to LaTeX for beginners that helps you ... 2017-04-22
wicked - Use wicked to turn your controller into a wizard ... 2017-04-22
flexboxfroggy - A game for learning CSS flexbox ... 2017-04-22

 Back to top