-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13d2bf3
commit 39a6c25
Showing
4 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
components/platerecognizer/actions/run-recognition/run-recognition.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import platerecognizer from "../../platerecognizer.app.mjs"; | ||
import { axios } from "@pipedream/platform"; | ||
|
||
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: platerecognizer.propDefinitions.imageFileOrUrl, | ||
regions: platerecognizer.propDefinitions.regions, | ||
cameraId: platerecognizer.propDefinitions.cameraId, | ||
mmc: platerecognizer.propDefinitions.mmc, | ||
config: platerecognizer.propDefinitions.config, | ||
}, | ||
async run({ $ }) { | ||
const formData = new FormData(); | ||
if (this.imageFileOrUrl.startsWith("http")) { | ||
formData.append("upload", this.imageFileOrUrl); | ||
} else { | ||
const fs = require("fs"); | ||
formData.append("upload", fs.createReadStream(this.imageFileOrUrl)); | ||
} | ||
if (this.regions) formData.append("regions", this.regions.join(",")); | ||
if (this.cameraId) formData.append("camera_id", this.cameraId); | ||
if (this.mmc !== undefined) formData.append("mmc", this.mmc); | ||
if (this.config) formData.append("config", this.config); | ||
|
||
const response = await axios(this, { | ||
method: "POST", | ||
url: `${this.platerecognizer._baseUrl()}/plate-reader/`, | ||
headers: { | ||
"Authorization": `Token ${this.platerecognizer.$auth.api_key}`, | ||
"Content-Type": "multipart/form-data", | ||
}, | ||
data: formData, | ||
maxContentLength: Infinity, | ||
maxBodyLength: Infinity, | ||
}); | ||
|
||
$.export("$summary", "Recognition process triggered successfully"); | ||
return response; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
"publishConfig": { | ||
"access": "public" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,74 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "platerecognizer", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
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. Use comma-separated values for multiple regions (e.g., us-ca,us-ny).", | ||
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: "string", | ||
label: "Config", | ||
description: "Additional configuration in JSON format.", | ||
optional: true, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
}, | ||
_baseUrl() { | ||
return "https://api.platerecognizer.com/v1"; | ||
}, | ||
async triggerRecognition({ | ||
imageFileOrUrl, regions, cameraId, mmc, config, | ||
}) { | ||
const formData = new FormData(); | ||
if (imageFileOrUrl.startsWith("http")) { | ||
formData.append("upload", imageFileOrUrl); | ||
} else { | ||
// Assuming the use of Node.js environment, fs should be used for local files | ||
// And since the file needs to be read as a stream, ensure fs is properly imported | ||
const fs = require("fs"); | ||
formData.append("upload", fs.createReadStream(imageFileOrUrl)); | ||
} | ||
if (regions) formData.append("regions", regions.join(",")); | ||
if (cameraId) formData.append("camera_id", cameraId); | ||
if (mmc !== undefined) formData.append("mmc", mmc); | ||
if (config) formData.append("config", config); | ||
|
||
return axios(this, { | ||
method: "POST", | ||
url: `${this._baseUrl()}/plate-reader/`, | ||
headers: { | ||
"Authorization": `Token ${this.$auth.api_key}`, | ||
"Content-Type": "multipart/form-data", | ||
}, | ||
data: formData, | ||
maxContentLength: Infinity, | ||
maxBodyLength: Infinity, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
56 changes: 56 additions & 0 deletions
56
components/platerecognizer/sources/new-recognition-instant/new-recognition-instant.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import platerecognizer from "../../platerecognizer.app.mjs"; | ||
|
||
export default { | ||
key: "platerecognizer-new-recognition-instant", | ||
name: "New Recognition Instant", | ||
description: "Emits new event when a cloud webhook event is broadcasted.", | ||
version: "0.0.{{ts}}", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
platerecognizer, | ||
db: "$.service.db", | ||
http: { | ||
type: "$.interface.http", | ||
customResponse: true, | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
console.log("Deploying new recognition instant source"); | ||
}, | ||
async activate() { | ||
console.log("Activating new recognition instant source"); | ||
}, | ||
async deactivate() { | ||
console.log("Deactivating new recognition instant source"); | ||
}, | ||
}, | ||
async run(event) { | ||
const body = event.body; | ||
if (!body) { | ||
this.http.respond({ | ||
status: 400, | ||
body: "No data received", | ||
}); | ||
return; | ||
} | ||
|
||
this.http.respond({ | ||
status: 200, | ||
body: "Success", | ||
}); | ||
|
||
const eventData = { | ||
hook: body.hook, | ||
data: body.data, | ||
}; | ||
|
||
this.$emit(eventData, { | ||
id: eventData.data.timestamp, | ||
summary: `New Recognition: ${eventData.data.results.map((result) => result.plate).join(", ")}`, | ||
ts: Date.parse(eventData.data.timestamp), | ||
}); | ||
}, | ||
}; |