# Convert keypoints to point2f to store in a file or localstorage

**URL:** <https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713>\
**Category:** Uncategorized\
**Tags:** javascript, opencvjs\
**Created:** [October 18, 2021, 10:51pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713 "2021-10-18T22:51:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremias](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jeremias](https://forum.opencv.org/u/jeremias)\
**Post date:** [October 18, 2021, 10:51pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/1 "2021-10-18T22:51:33Z")

</div>

Hi! 🙂  
according to the documentation, its possible to convert an KeyPoint into a point2f…

Well im trying to convert an array of keyPoints from cvOrb.

```auto
let orb = new cv.ORB();
    orb.setMaxFeatures(MAX_FEATURES);

    cv.cvtColor(object.im, object.gray, cv.COLOR_RGBA2GRAY, 0);
    orb.detectAndCompute(object.gray, new cv.Mat(), object.kp, object.descriptors);

    let t = new cv.Mat();
    object.kp.convertTo(t, )

```

basically i want to known how-to convert in javascript! 🙂

[https://docs.opencv.org/4.5.3/d2/d29/classcv\_1\_1KeyPoint.html#acfcc8e0dd1a634a7583686e18d372237](https://docs.opencv.org/4.5.3/d2/d29/classcv_1_1KeyPoint.html#acfcc8e0dd1a634a7583686e18d372237)

other alternative would be to use filestorage to store the keypoints as yaml

[https://answers.opencv.org/question/4040/to-save-vector-keypoint-to-file-using-builtin-write-function/](https://answers.opencv.org/question/4040/to-save-vector-keypoint-to-file-using-builtin-write-function/)

I didn’t find any example, and try to check the bindings and source code, but didn’t get far. is this even possible? thanks.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 19, 2021, 7:10am UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/2 "2021-10-19T07:10:57Z")

</div>

may i ask, _why_ you want to do this ?  
what do you plan to do with the point locations ?  
(you’d basically make a loop and extract the `pt` member from each keypoint)

then, you’re usually not allowed to access the file system from js,  
and it’s the same here - [no FileStorage](https://github.com/opencv/opencv/blob/master/platforms/js/opencv_js.config.py)

---

<div class="post-metadata">

**Author:** ![jeremias](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jeremias](https://forum.opencv.org/u/jeremias)\
**Post date:** [October 19, 2021, 10:03am UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/3 "2021-10-19T10:03:31Z")

</div>

well, i want to do this, because i need to load 40 images everytime i start this app… and it takes time to generate all the keypoints needed. then i could boost the load of the app 🙂  
instead of needing to load all the images, i could just load a file with keypoints, and the features matrix.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 19, 2021, 10:32am UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/4 "2021-10-19T10:32:08Z")

</div>

> [@jeremias](#):
>
> i need to load 40 images everytime i start this app… and it takes time to generate all the keypoints needed

well, the matching uses descriptors _only_ , so it’s far more imprtant to save those

last, this sounds, like you ty to match a query image to a “gallery” – what is the purpose of it ? if it’s “finding similar images”, you’re probably on the wrong bus, the [matching process here](https://docs.opencv.org/master/d5/d6f/tutorial_feature_flann_matcher.html) is the wrong approach for that (lookup “BagOfWords” then)

---

<div class="post-metadata">

**Author:** ![jeremias](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jeremias](https://forum.opencv.org/u/jeremias)\
**Post date:** [October 19, 2021, 6:38pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/5 "2021-10-19T18:38:48Z")

</div>

are you sure? In here the ORB detectAndCompute is using the keypoints.

`this.matcher.orb.detectAndCompute(this.scene.gray, new cv.Mat(), this.scene.kp, this.scene.descriptors);`

Anyway I am more focus on just solving on how-to store the keypoints, not on how to detect Images. because that has been debated before and we are happy ORB for our purpose. Anyway i didn’t understand what is your suggestion about that. can you make it more clear? 🙂 thanks

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 19, 2021, 6:48pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/6 "2021-10-19T18:48:11Z")

</div>

> [@jeremias](#):
>
> detectAndCompute is using the keypoints

it is _calculating_ keypoints here, not using presupplied ones

> [@jeremias](#):
>
> and we are happy ORB for our purpose.

finally tell us, what _that_ is. (i think, i asked 2 times already …)

---

<div class="post-metadata">

**Author:** ![jeremias](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jeremias](https://forum.opencv.org/u/jeremias)\
**Post date:** [October 19, 2021, 6:51pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/7 "2021-10-19T18:51:13Z")

</div>

you are absolutely correct! thanks 🙂

sorry i didnt explain. so we have a collection of many images that need to be detect using a camera in the real world. When an image is detected the app will redirect the person to a specific url, image, sound, video, or even an AR mode using jsartoolkit5 😉

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 19, 2021, 6:58pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/8 "2021-10-19T18:58:47Z")

</div>

> [@jeremias](#):
>
> we have a collection of many images that need to be detect using a camera in the real world.

do you have an example of an “image that needs to be detected” and another “using a camera in the real world.” one ?

do you have any _code_ proving your idea works ? how would you measure “similarity” here ?

---

<div class="post-metadata">

**Author:** ![jeremias](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jeremias](https://forum.opencv.org/u/jeremias)\
**Post date:** [October 20, 2021, 12:00pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/9 "2021-10-20T12:00:19Z")

</div>

I released this code (the example is not working yet):

> **[GitHub - albjeremias/trigger-cv: use images to train opencv to detect them on...](https://github.com/albjeremias/trigger-cv)**
>
> use images to train opencv to detect them on the real world. - GitHub - albjeremias/trigger-cv: use images to train opencv to detect them on the real world.

So **similarity** is measured in here:

> <https://github.com/albjeremias/trigger-cv/blob/main/trigger-cv.js#L61>

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 20, 2021, 12:39pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/10 "2021-10-20T12:39:48Z")

</div>

nice, that you could finish this (without any docs or tuts !)  
we now also have a working js example for feature matching here, good !  
(ppl _will_ come for this !)

as long as ALL your images come from the (same) camera, it might even give meaningful matching results (just DONT add a feature, where users can upload their own images, then it’ll break, comparing apples to pears)

---

<div class="post-metadata">

**Author:** ![jeremias](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jeremias](https://forum.opencv.org/u/jeremias)\
**Post date:** [October 20, 2021, 12:41pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/11 "2021-10-20T12:41:19Z")

</div>

im finishing up an example on how-to to use it 🙂  
what do you mean from the same camera? it works with many different setups. lemme finish this example 🙂  
I used many tutorials, and different stuff. opencv is cool!

---

<div class="post-metadata">

**Author:** ![jeremias](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jeremias](https://forum.opencv.org/u/jeremias)\
**Post date:** [October 20, 2021, 3:41pm UTC](https://forum.opencv.org/t/convert-keypoints-to-point2f-to-store-in-a-file-or-localstorage/5713/12 "2021-10-20T15:41:30Z")

</div>

its working now 🙂 you can test it here:  
[https://albjeremias.github.io/trigger-cv/example/index.htm](https://albjeremias.github.io/trigger-cv/example/index.htm)

So what i want to do is to store the object descriptors in the local storage of the browser or as a file (generated previously)

> <https://github.com/albjeremias/trigger-cv/blob/main/trigger-cv.js#L298>

I wonder if generating it previously bring problems, but i will make some tests. the issue is that i use the videoWidth to calculate the descriptors, but it seems a bit irrelevant, since the image size changes on the camera image too…
