Lens
Google Lens is famous and powerful for image search. Users could use its fancy UI for image selection. I like its effect and wanna to apply it for services I owned. That's also the main reason I wrapped it into <msc-lens />
.
Developers could received exactly the image which users just selected and do some analytics and recommend. Then render results through event which <msc-lens />
provided.
Check the following demos and see what can <msc-lens />
do.(first one comes with a preview window to indicate which part will send.)
Above images apply TensorFlow Object Detection technology.
Basic Usage
<msc-lens />
is a web component. All we need to do is put the required script into your HTML document. Then follow <msc-lens />
's html structure and everything will be all set.
Required Script
Structure
Put img[slot="msc-lens-vision"]
inside <msc-lens />
as its child.
It will use it as source.
Otherwise, developers could also choose remoteconfig to fetch config for <msc-lens />
.
JavaScript Instantiation
<msc-lens />
could also use JavaScript to create DOM element. Here comes some examples.
Style Customization
<msc-lens />
uses CSS variables to style its interface. That means developer could easy change them into the lookup you like.
Attributes
<msc-lens />
supports some attributes to let it become more convenience & useful.
sensorsize
Set sersor size for <msc-lens />
. Default is 28 (px).
active
Set active for <msc-lens />
. It will switch to select mode once set. Default is false (not set).
delay
Set delay for <msc-lens />
. It will delay fetch web service once user finish select. Default is 500 (ms).
format
Set image format for <msc-lens />
. This attribute can only accept "blob" or "dataURL". Default is "blob".
webservice
Set web service information for <msc-lens />
. It should be JSON string. Developers could set uri、fieldName and extra params here.(uri must be full path)
boundings
Set boundings information for <msc-lens />
. Developers could defined objects' bounding information through this. Each unit should be JSON string and required top、right、bottom、left(percentage). When <msc-lens /> active, there will be some indicators display.
Properties
Property Name | Type | Description |
---|---|---|
sensorsize
|
Number | Getter / Setter for senser size. Developers could use this property to setup sensor size. |
active
|
Boolean | Getter / Setter for active. It will switch to select / normal mode. |
delay
|
Number | Getter / Setter for delay. It will delay fetch web service once user finish select. |
format
|
String | Getter / Setter for format. It will set image format. This property can only accept "blob" or "dataURL". Default is "blob". |
webservice
|
Object | Getter / Setter for web service information. Developers could set uri、fieldName and extra params here.(uri must be full path) |
boundings
|
Object | Getter / Setter for object bounding information. Developers could defined objects' bounding information in top、right、bottom、left.(percentage) |
Method
Methos Signature | Description |
---|---|
toggle([force])
|
Toggle <msc-lens /> select or normal mode. When argument is present: If the argument is true, <msc-lens /> will switch to select mode, and if it is false, back to normal. |
switchSource(source-address)
|
Switch <msc-lens /> image source.(this is an async method) |
Events
Event Signature | Description |
---|---|
msc-lens-switch
|
Fired when <msc-lens /> mode switched. Developers could get active through event.detail . |
msc-lens-capture
|
Fired when <msc-lens /> captures image selection. Developers could get image、bounding through event.detail . |
msc-lens-process
|
Fired when <msc-lens /> fetch web service. |
msc-lens-switching
|
Fired when <msc-lens /> switch image source. |
msc-lens-switchend
|
Fired when <msc-lens /> switch image source end. |
msc-lens-result
|
Fired when <msc-lens /> finished web service fetching. Developers could get result through event.detail . |