Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/5v1988/glancer-js
This is a project to compare images using opencv. This is based on rest-api
https://github.com/5v1988/glancer-js
Last synced: 3 days ago
JSON representation
This is a project to compare images using opencv. This is based on rest-api
- Host: GitHub
- URL: https://github.com/5v1988/glancer-js
- Owner: 5v1988
- License: apache-2.0
- Created: 2024-03-30T06:58:28.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-04-13T12:18:31.000Z (7 months ago)
- Last Synced: 2024-04-14T02:18:54.983Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.19 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Glancer-JS
## Highlight
Before going any further, let's try to spot, among the three images in this folder: `src/test-images`, which two images are the same and which two are different.
Not so easy, right?
This project — based on rest-api, lets you compare them using [open-cv](https://opencv.org/), given any two images. Furthermore, it also lets you set the tolerance by which the difference between them will be considered either pass or fail. This benefits while performing visual testing/regression in both development and qa testing
### Sample Request
```curl
curl --location 'https://www.qualityplus.io/api/glance?threshold=0.5' \
--header 'content-type: multipart/form-data' \
--form 'images=@"/path/to/snapshot/im-3.png"' \
--form 'images=@"/path/to/snapshot/im-4.png"'
```### Sample Response
```json
{
"threshold": 0.5,
"match": false,
"mean_squared_err": 43.22
}
```### Java Client
```java
package io.qualityplus.clients;public class GlancingResponse {
public double threshold;
public boolean match;
public double mean_squared_err;
}```
```java
package io.qualityplus.clients;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.Response;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.MultiPart;
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
import java.io.File;
import java.io.IOException;public class GlancingClient {
private static final String BASE_URI = "https://www.qualityplus.io/api/glance";
private final Client client = ClientBuilder.newClient();
public GlancingResponse glanceImages(String img1, String img2, float threshold) {
FileDataBodyPart image1 = new FileDataBodyPart("images", new File(img1));
FileDataBodyPart image2 = new FileDataBodyPart("images", new File(img2));
Response response;
try (MultiPart multipartEntity = new FormDataMultiPart().bodyPart(image1)
.bodyPart(image2)) {
response = client.target(BASE_URI)
.queryParam("threshold", String.valueOf(threshold))
.request()
.post(Entity.entity(multipartEntity, multipartEntity.getMediaType()));
} catch (IOException e) {
throw new RuntimeException(e);
}
client.close();
return response.readEntity(GlancingResponse.class);
}
}```
### Test example
```java
public class GlancingTest {
GlancingClient client = new GlancingClient();
@Test(description = "Compare images")
public void glanceImages() {
GlancingResponse response = client.glanceImages("snapshots/image-3.png",
"snapshots/image-4.png", 5);
System.out.printf("Threshold: %s, Match: %s, Mean Squared Error: %s%n",
response.threshold,
response.match,
response.mean_squared_err);
Assert.assertTrue(response.match, "the given images are matched!");
}
}Of course, we delete all snapshots soon we are done with them, so you are safe too!
```
### Support
- [GitHub issues](https://github.com/5v1988/glancer-js/issues)
- Contact options listed on [this GitHub profile](https://github.com/5v1988)
- [Discord](https://discord.gg/GWfMu5Cwq6)