Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand usage of OpenCV.js-based modules #237

Open
jywarren opened this issue May 3, 2018 · 20 comments
Open

Expand usage of OpenCV.js-based modules #237

jywarren opened this issue May 3, 2018 · 20 comments

Comments

@jywarren
Copy link
Member

jywarren commented May 3, 2018

Let's start by attempting to include OpenCV.js and do some simple operation with it:

https://docs.opencv.org/3.4.1/dd/d4d/tutorial_js_image_arithmetics.html

Thanks @abTest-123 -- https://publiclab.org/notes/amirberAgain/01-12-2018/python-and-opencv-to-analyze-microscope-slide-images-of-airborne-particles#c19541

@MargaretAN9
Copy link

MargaretAN9 commented Aug 19, 2018

@warren

I used the SciPy library for the sobel filter in the microscope video
https://publiclab.org/notes/MaggPi/08-14-2018/computer-vision-observations-of-elodea-plant-cells
I used this example because it showed how to merge the x and y filters.

http://www.turbare.net/transl/scipy-lecture-notes/advanced/image_processing/auto_examples/plot_find_edges.html
I realize now I could have probably done this with opencv , but the example never showed how to combine x and y.
The opencv sobel filter is below (In python)
https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_gradients/py_gradients.html

Not sure which one is fastest

@jywarren
Copy link
Member Author

jywarren commented Sep 11, 2018

oh cool!

@jywarren
Copy link
Member Author

jywarren commented Sep 11, 2018

(moving these comments on interest point matching to #300!)

@abTest-123
Copy link

abTest-123 commented Sep 12, 2018 via email

@jywarren
Copy link
Member Author

jywarren commented Sep 12, 2018 via email

@Mridul97
Copy link

Mridul97 commented Nov 13, 2018

Hey, I used OpenCV.js to add two images. It took two images as input. The tulips image below was given twice as both the inputs. Please have a look! 😃
tulips

And I got this image as output.
output

@jywarren
Copy link
Member Author

jywarren commented Nov 13, 2018 via email

@Mridul97
Copy link

Mridul97 commented Nov 13, 2018

No, It is not integrated into image sequencer. It is just a demo. Link of the gist :- https://gist.github.com/Mridul97/8588a6029b54942cd319605ad7a3917a
Please have a look! 😃

@jywarren
Copy link
Member Author

jywarren commented Nov 13, 2018

Wow, but this is pretty simple (i simplified it a bit more even, and we'll have to watch asynchronous events):

mat1 = cv.imread(imgElement1);
mat2 = cv.imread(imgElement2);

let dst = new cv.Mat();
let mask = new cv.Mat();
let dtype = -1;
cv.add(mat1, mat2, dst, mask, dtype);
cv.imshow('canvasOutput1', dst);
mat1.delete(); 
mat2.delete(); 
dst.delete(); 
mask.delete();

Where is the cv variable defined?

In any case, this seems like it could be a pretty easy module to implement. But does it have to output to a canvas? canvasOutput1? Could we have it output an image object, or ImageData, or a data-url?

@jywarren
Copy link
Member Author

Looking at https://docs.opencv.org/3.4.1/df/d24/tutorial_js_image_display.html ... maybe imshow is not canvas-specific?

@jywarren
Copy link
Member Author

I saw there's a matFromImageData function, and am looking for a matching matToImageData function...

@jywarren
Copy link
Member Author

You might also inspect what cv.imshow does in the source... i couldn't find this. Or inspect what's inside of mat1 and cv to see if we can parse it out ourselves?

@jywarren
Copy link
Member Author

Oh awesome. So mat1.data is a Uint8Array(409600) -- we can work with that!

Maybe some help here:

This is cool!

Note that opencv.js weighed 11 mb... whoa. But still potentially worth it!!!

@Mridul97
Copy link

Mridul97 commented Nov 13, 2018

Yes, we can access and modify pixel values using mat.data!! Something like this:

let row = 3, col = 4;
let src = cv.imread("canvasInput");
if (src.isContinuous()) {
    let R = src.data[row * src.cols * src.channels() + col * src.channels()];
    let G = src.data[row * src.cols * src.channels() + col * src.channels() + 1];
    let B = src.data[row * src.cols * src.channels() + col * src.channels() + 2];
    let A = src.data[row * src.cols * src.channels() + col * src.channels() + 3];
}

cv is actually defined in OpenCV.js.

We can also convert it to Uint8Array:

let arr = new Uint8ClampedArray(dst.data, dst.cols, dst.rows);

@MargaretAN9
Copy link

@jywarren Is openv.js installed on image sequencer? if so what version? If not, has anyway tried to install such as
https://docs.opencv.org/3.4/d4/da1/tutorial_js_setup.html ??

After install, need to determine if capture video and stitcher commands will work with public lab cameras.....

@jywarren
Copy link
Member Author

jywarren commented Mar 30, 2019 via email

@jywarren
Copy link
Member Author

OpenCV is installed now! See https://github.com/publiclab/image-sequencer/blob/main/src/modules/BlobAnalysis/BlobAnalysis.js for examples. Let's expand out from this initial example!

@jywarren jywarren changed the title Explore OpenCV.js module Expand usage of OpenCV.js-based modules Jan 28, 2020
@jywarren
Copy link
Member Author

Noting for context!!!

one issue I think was that there are pretty few WASM compilations available. we had to use an older version of OpenCV that someone had WASM compiled

This was all achieved by @aashna27 in #1185

@jywarren
Copy link
Member Author

Uhhh, strangely it's not in the demo or the beta: https://sequencer.publiclab.org/examples/ https://beta.sequencer.publiclab.org/examples/

Though it definitely works in Aashna's demo: https://aashna27.github.io/image-sequencer/examples/#steps=brightness{},brightness{},blob-analysis{}

@aashna27 are you able to take a look to see how it got removed? And, we should add a test like this one to protect it!

https://github.com/publiclab/image-sequencer/blob/89fb3585ac082c6bce3cd72640ec2be9f75df5f0/test/core/modules/colorbar.js

@jywarren
Copy link
Member Author

Solved -- it was a cache issue -- and opened an issue to request a module test for it: #1587

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants