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

New Components - platerecognizer #11944

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import fs from "fs";
import { checkTmp } from "../../common/utils.mjs";
import platerecognizer from "../../platerecognizer.app.mjs";

export default {
key: "platerecognizer-run-recognition",
name: "Run Recognition",
description: "Triggers a recognition process using the Plate Recognizer SDK.",
version: "0.0.1",
type: "action",
props: {
platerecognizer,
imageFileOrUrl: {
type: "string",
label: "Image File or URL",
description: "The image file or URL to be recognized.",
},
regions: {
type: "string[]",
label: "Regions",
description: "Regions to select specific license plate patterns. [See further details here](https://guides.platerecognizer.com/docs/other/country-codes/#country-codes)",
optional: true,
},
cameraId: {
type: "string",
label: "Camera ID",
description: "The ID of the camera that took the image.",
optional: true,
},
mmc: {
type: "boolean",
label: "MMC",
description: "Whether to detect vehicle make, model, and color.",
optional: true,
},
config: {
type: "object",
label: "Config",
description: "Additional configuration. [See further details here](https://guides.platerecognizer.com/docs/snapshot/api-reference/#engine-configuration)",
optional: true,
},
},
async run({ $ }) {
const fileObj = {};

if (this.imageFileOrUrl.startsWith("http")) {
fileObj.upload_url = this.imageFileOrUrl;
} else {
const file = fs.readFileSync(checkTmp(this.imageFileOrUrl));
fileObj.upload = Buffer(file).toString("base64");
}

const response = await this.platerecognizer.runRecognition({
$,
data: {
...fileObj,
regions: this.regions,
camera_id: this.cameraId,
mmc: this.mmc,
config: this.config,
},
});

$.export("$summary", "Recognition process triggered successfully");
return response;
},
};
6 changes: 6 additions & 0 deletions components/platerecognizer/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const checkTmp = (filename) => {
if (!filename.startsWith("/tmp")) {
return `/tmp/${filename}`;
}
return filename;
};
8 changes: 6 additions & 2 deletions components/platerecognizer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/platerecognizer",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Plate Recognizer Components",
"main": "platerecognizer.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.5"
}
}
}

32 changes: 27 additions & 5 deletions components/platerecognizer/platerecognizer.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "platerecognizer",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.platerecognizer.com/v1";
},
_headers(headers) {
return {
"Authorization": `Token ${this.$auth.api_token}`,
...headers,
};
},
_makeRequest({
$ = this, path, headers = {}, ...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: this._headers(headers),
...opts,
});
},
runRecognition(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/plate-reader/",
...opts,
});
},
},
};
};
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading