{"_id":"@anpanman/opencv_ts","_rev":"4-1ed491e52d0b88236c6c67e426a095c6","name":"@anpanman/opencv_ts","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@anpanman/opencv_ts","version":"1.0.0","description":"Experimental WIP TypeScript typings and OpenCV.js/wasm loader.","private":false,"license":"MIT","main":"index.js","typings":"./lib/index.d.ts","scripts":{"test":"node --enable-source-maps --liftoff --no-wasm-tier-up ./node_modules/qunit/bin/qunit.js dist/tests","test:single":"node --enable-source-maps --liftoff --no-wasm-tier-up ./node_modules/qunit/bin/qunit.js","gen:types":"python ./ts_generator/typegen.py","watch:test":"tsc --watch -p ./tsconfig.test.json"},"optionalDependencies":{},"devDependencies":{"@types/node":"^14.14.20","@types/qunit":"^2.11.1","@typescript-eslint/eslint-plugin":"^4.11.1","@typescript-eslint/parser":"^4.11.1","eslint":"^7.17.0","qunit":"^2.13.0","typescript":"^4.1.3"},"directories":{"lib":"lib","test":"tests"},"repository":{"type":"git","url":"git+https://github.com/peteruhnak/opencv-ts.git"},"keywords":["opencv","ts"],"author":"","bugs":{"url":"https://github.com/peteruhnak/opencv-ts/issues"},"homepage":"https://github.com/peteruhnak/opencv-ts#readme","gitHead":"da6e203b7fdf26249ee0c494f93d407b0f393003","dependencies":{},"_id":"@anpanman/opencv_ts@1.0.0","_nodeVersion":"16.10.0","_npmVersion":"7.24.1","dist":{"integrity":"sha512-oflzxJvdFusGoOv0d1/P2IkmaPxwdA8fQBozR9mh8TKu76H7wNSTcR4c2FY7PC/IbprqJg6E3gDm1z6vTWnIJw==","shasum":"b2e6279ebb005a7949fcfb7793ce792ad391dc83","tarball":"https://registry.npmjs.org/@anpanman/opencv_ts/-/opencv_ts-1.0.0.tgz","fileCount":44,"unpackedSize":15308295,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCU9siGLLubgaVnX+JJXk2eV/EYEM7n2hLtNBRpd5xLdwIgDVPSJJAiRm6qzH11lmQePfufBrLxtNIb70A0g/xi6iU="}]},"_npmUser":{"name":"anpanman","email":"stratoss@gmail.com"},"maintainers":[{"name":"anpanman","email":"stratoss@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/opencv_ts_1.0.0_1634807397316_0.8662170235319853"},"_hasShrinkwrap":false},"1.0.1":{"name":"@anpanman/opencv_ts","version":"1.0.1","description":"Experimental WIP TypeScript typings and OpenCV.js/wasm loader.","private":false,"license":"MIT","main":"index.js","typings":"./lib/index.d.ts","scripts":{"test":"node --enable-source-maps --liftoff --no-wasm-tier-up ./node_modules/qunit/bin/qunit.js dist/tests","test:single":"node --enable-source-maps --liftoff --no-wasm-tier-up ./node_modules/qunit/bin/qunit.js","gen:types":"python ./ts_generator/typegen.py","watch:test":"tsc --watch -p ./tsconfig.test.json"},"optionalDependencies":{},"devDependencies":{"@types/node":"^14.14.20","@types/qunit":"^2.11.1","@typescript-eslint/eslint-plugin":"^4.11.1","@typescript-eslint/parser":"^4.11.1","eslint":"^7.17.0","qunit":"^2.13.0","typescript":"^4.1.3"},"directories":{"lib":"lib","test":"tests"},"repository":{"type":"git","url":"git+https://github.com/peteruhnak/opencv-ts.git"},"keywords":["opencv","ts"],"author":"","bugs":{"url":"https://github.com/peteruhnak/opencv-ts/issues"},"homepage":"https://github.com/peteruhnak/opencv-ts#readme","gitHead":"da6e203b7fdf26249ee0c494f93d407b0f393003","dependencies":{},"_id":"@anpanman/opencv_ts@1.0.1","_nodeVersion":"16.10.0","_npmVersion":"7.24.1","dist":{"integrity":"sha512-YsHX1B3IZBbQM/JY4ookwY3BI1zQnHpoOUC8FOU4F35AyKrSqKZXRydaopYUDU4pT1GZ0+KqNrhseND+rNs1ww==","shasum":"b22ae4666fb9db5f1a347423629e338278017ce1","tarball":"https://registry.npmjs.org/@anpanman/opencv_ts/-/opencv_ts-1.0.1.tgz","fileCount":44,"unpackedSize":15308277,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICE1aYuXyPcK8ZC4uuO5Jqv+wcjJmTuIPL2jyuLCzvijAiBeq32NDWgh7hLjeazUfsFNg5ypn5m0stXK9lVitHL7uQ=="}]},"_npmUser":{"name":"anpanman","email":"stratoss@gmail.com"},"maintainers":[{"name":"anpanman","email":"stratoss@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/opencv_ts_1.0.1_1634821541166_0.05768647539616989"},"_hasShrinkwrap":false},"1.0.2":{"name":"@anpanman/opencv_ts","version":"1.0.2","description":"Experimental WIP TypeScript typings and OpenCV.js/wasm loader.","private":false,"license":"MIT","main":"index.js","typings":"./lib/index.d.ts","scripts":{"test":"node --enable-source-maps --liftoff --no-wasm-tier-up ./node_modules/qunit/bin/qunit.js dist/tests","test:single":"node --enable-source-maps --liftoff --no-wasm-tier-up ./node_modules/qunit/bin/qunit.js","gen:types":"python ./ts_generator/typegen.py","watch:test":"tsc --watch -p ./tsconfig.test.json"},"optionalDependencies":{},"devDependencies":{"@types/node":"^14.14.20","@types/qunit":"^2.11.1","@typescript-eslint/eslint-plugin":"^4.11.1","@typescript-eslint/parser":"^4.11.1","eslint":"^7.17.0","qunit":"^2.13.0","typescript":"^4.1.3"},"directories":{"lib":"lib","test":"tests"},"repository":{"type":"git","url":"git+https://github.com/peteruhnak/opencv-ts.git"},"keywords":["opencv","ts"],"author":"","bugs":{"url":"https://github.com/peteruhnak/opencv-ts/issues"},"homepage":"https://github.com/peteruhnak/opencv-ts#readme","gitHead":"da6e203b7fdf26249ee0c494f93d407b0f393003","dependencies":{},"_id":"@anpanman/opencv_ts@1.0.2","_nodeVersion":"16.10.0","_npmVersion":"7.24.1","dist":{"integrity":"sha512-owZky1DPf5nADu2i/S/Ei4u8K88oictRZazlSaZVsJ2Kk5DOjR7Cj32BZxd1pGc2CUD1mJVOfQGdXaB80uYmnA==","shasum":"c09d075b5040baf325f8d5b45599b6a183be907c","tarball":"https://registry.npmjs.org/@anpanman/opencv_ts/-/opencv_ts-1.0.2.tgz","fileCount":44,"unpackedSize":15308279,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhwyMxCRA9TVsSAnZWagAA/CsP+QEIKxQF6wJarxDX5qvv\nJEmpMbsg3mh+yBdUyQNr/+Mbr5YPc0sh0Pm03B6X0Jfb9kswAcBnb9/ms3Cu\nFsc9272JAoSn/y78zM9d+clCVMkrfPS/byVugS2TnySgoTxs/VX2ZIXDz46o\n0d7EW5hxpSjAl4MOxP5A4ZrZDCzIgKRHA4WosfeEEs9462RLNwEjR3a8OnnI\n7oFnZsh+7suujnEeLsxbN9969DP8/HlNqcBQETwqpBaeOe1SOLX3jpuk3EDm\npn7uNxXN82JFTuP0mABP9TTjgoCPnA6XcZMmJOAS3QJudr3lpyuFAjhRBTGO\nv7FPX394vLyH6Cc8jcASz+hZFquimKLkRJ4hlDuto0kOJlThJ6fkgyqyXZoh\nMMBfHCv3T5UWpzQiyC8i9Cl0okrdPIqnoWkcFekni4EpqkCA3A9b80Ad2IY3\nS43i1rLz9AWfZmu4A6xAR7p3YNCZ79zaynuCby2dOpRz2WMhApEWf7qQybrT\n9UeC83xdN+ijezEh4p6ma1/VTCKx7xnlL3MdLyXqPQmq7eDXMvV8gMrCzjf/\nGUIUaBZKOzIahFrqiAivLoqKi1cjOLgpI8Ru8VpAsN+rRYzUFu1HbIvyhv+v\nRpzOdlSsgtw/6SyzpTzHFs6sNN0bWn4bUn5wbO3wcV1LImVujDE9ef1Hv4ox\npK//\r\n=MhmE\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCw1owhbbkNzkQSUT0fxsQ02J6gRvtdCpMC+jZ+yBrm4wIhAKekKBjrYE42oxpGj/+gO8fI660K5FVf8+iBEpq5Qn4V"}]},"_npmUser":{"name":"anpanman","email":"stratoss@gmail.com"},"maintainers":[{"name":"anpanman","email":"stratoss@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/opencv_ts_1.0.2_1634821595256_0.49054817130249706"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-21T09:09:57.199Z","1.0.0":"2021-10-21T09:09:57.602Z","modified":"2022-04-04T14:19:20.758Z","1.0.1":"2021-10-21T13:05:41.435Z","1.0.2":"2021-10-21T13:06:35.500Z"},"maintainers":[{"name":"anpanman","email":"stratoss@gmail.com"}],"description":"Experimental WIP TypeScript typings and OpenCV.js/wasm loader.","homepage":"https://github.com/peteruhnak/opencv-ts#readme","keywords":["opencv","ts"],"repository":{"type":"git","url":"git+https://github.com/peteruhnak/opencv-ts.git"},"bugs":{"url":"https://github.com/peteruhnak/opencv-ts/issues"},"license":"MIT","readme":"# OpenCV-TS\n\nExperimental WIP TypeScript typings and OpenCV.js/wasm loader.\n\nTypings in this repository are generated by reusing/extending OpenCV python and embindgen generators.\nThis approach makes it easier to ensure the typings actually match the wasm, as well as being able to reuse documentation in C++ headers.\n\n## Contents\n\nMain opencv-ts contents:\n\n* hand-written `lib/typings/core` for hand-written `core_bindings.cpp`\n* generated `lib/typings/gen` from wasm build of opencv\n* pretty-printed `lib/_opencv.js` (to avoid generating massive stacktraces in Node 14)\n* generator invoker `ts_generator/typegen.py`\n* `tests/opencv` are copied from `opencv` and converted to typescript mainly to test typings and find missing stuff\n\n## Running Tests\n\n1. clone repo && npm install\n2. compile tests `npm run watch:test`\n3. run all tests `npm run test`\n\nOr run a single test file `npm run test:single dist/tests/opencv/test_calib3d.js`\n\n\n## Usage\n\n1. Clone this repository https://github.com/peteruhnak/opencv-ts\n2. `npm install /your/clone/dir/opencv-ts`\n\nTo use opencv in node, the library/wasm must be fully initialized, which may take a moment.\nThis library wraps emscripten's `onRuntimeInitialized` in a Promise-based loader `cv.loadOpenCV(): Promise<void>`.\n\n* import the library as `import cv from 'opencv'`\n* await promise `cv.loadOpenCV()` before doing anything\n  * the loader does some derpy stuff to ensure `loadOpenCV` is reentrant, but loaded only once\n* you must access cv objects and types through `cv`\n  * e.g. `import { Mat } from 'opencv'` will not work\n\n\n### Node Example\n\nUses `pngjs` to serialize image.\n\n`cv-test.ts`:\n\n```typescript\nimport cv from 'opencv'\nimport { PNG } from 'pngjs'\nimport fs from 'fs'\n\nfunction matToDataUrl(mat: cv.Mat): string {\n  const size = mat.size()\n  const png = new PNG({ width: size.width, height: size.height })\n  png.data.set(mat.data)\n  const buffer = PNG.sync.write(png)\n  return 'data:image/png;base64,' + buffer.toString('base64')\n}\n\ncv.loadOpenCV().then(() => {\n  const baseMatSrc = new cv.Mat(2, 4, cv.CV_8UC3)\n  baseMatSrc.data.set(new Uint8Array([\n    255, 0, 0, 0, 255, 0, 0, 0,\n    255, 255, 255, 255, 255, 0, 255, 0,\n    255, 255, 255, 255, 0, 0, 0, 0\n  ]))\n  const baseMat = new cv.Mat()\n  cv.cvtColor(baseMatSrc, baseMat, cv.COLOR_RGB2RGBA)\n  const largerMat = new cv.Mat()\n  cv.resize(baseMat, largerMat, { width: 20 * baseMat.cols, height: 20 * baseMat.rows }, 0, 0, cv.INTER_NEAREST)\n\n  const contents = `\n    <p>\n    base:<br>\n    <img src=\"${matToDataUrl(baseMat)}\">\n    <p>\n    larger:<br>\n    <img src=\"${matToDataUrl(largerMat)}\">\n    `\n  fs.writeFileSync('out.html', contents)\n  console.log('written to out.html')\n\n  baseMatSrc.delete()\n  baseMat.delete()\n  largerMat.delete()\n})\n```\n\n```\nts-node cv-test.ts\n```\n\nOpen `out.html` in browser.\n\n\n### Rebuilding Sources\n\n* Clone this repository https://github.com/peteruhnak/opencv-ts\n* Clone `master` branch of https://github.com/opencv/opencv\n* Clone `ts-experimental` branch of https://github.com/peteruhnak/opencv\n\n### OpenCV.js\n\nBuild (master) of `opencv/opencv` -- follow https://docs.opencv.org/master/d4/da1/tutorial_js_setup.html but use emsdk `1.39.0-upstream` (See also https://github.com/opencv/opencv/issues/19243 )\n\nYou can probably build from `ts-experimental` instead, but changes in `embindgen.py` may be unstable.\n\n### Typings\n\nModify paths in `ts_generator/typegen.py`:\n\n* `opencv_path = \"D:/prog/opencv\"` <- `ts-experimental` opencv clone\n* `build_js_path = \"D:/prog/github/build_js\"` <- compiled opencv.js directory\n* `ts_gen_path = \"D:/prog/opencv-ts/lib/typings/gen\"` <- where to generate typings (`lib/typings/gen` of this repository)\n* `replace_wsl = True` <- applicable when running gen on Windows, but opencv.js was compiled via WSL\n\nRun `npm run gen:types`.\n\nNote: Only Python 3.x is supported. \n\n### What Is Where\n\nThe actual generator in `ts-experimental` of peteruhnak/opencv consists of:\n\n* `modules/js/generator/jsgen.py`\n  * this is code extracted from `enbindgen.py` and modified so it can be actually imported from other modules\n  * adds docstring from `hdr_parser.py` (c++ header parser) to FuncVariant & ClassInfo\n  * this file is normally responsible for generating `bindings.cpp`\n* `modules/js/generator/tsgen.py`\n  * uses data constructed by `jsgen.py`/`JSWrapperGenerator` (Namespaces, ClassInfo, ...)\n  * generates TypeScript files","readmeFilename":"README.md"}