-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
205 additions
and
57 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/opencv | ||
/output | ||
Cargo.lock | ||
config/aicam.toml |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
name = "aicam" | ||
version = "0.1.0" | ||
edition = "2021" | ||
description = "AI face detection app based on opencv and libfacedetection libs" | ||
description = "AI face detection & notification app (opencv + libfacedetection)" | ||
authors = ["Vi+ <[email protected]>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
@@ -13,10 +13,13 @@ path = "src/main.rs" | |
|
||
[dependencies] | ||
libfacedetection = { path = "./libfacedetection-rs/libfacedetection-rs" } | ||
thiserror = "1.0.57" | ||
opencv = "0.88.8" | ||
chrono = "0.4.34" | ||
serde = "1.0.197" | ||
toml = "0.8.10" | ||
argh = "0.1.12" | ||
once_cell = "1.19.0" | ||
log = "0.4.21" | ||
env_logger = "0.11.2" | ||
reqwest = { version = "0.11.24", features = ["blocking", "json", "multipart"] } | ||
tokio = { version = "1.36.0", features = ["full"] } |
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
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,5 +1,10 @@ | ||
[general] | ||
device = "/dev/video0" | ||
confidence = 30 # 50 | ||
device_name = "Cam #1" | ||
confidence = 30 | ||
post_frames_amount = 3 | ||
output_dir = "./output" | ||
debug = true | ||
|
||
[telegram] | ||
token = "TT" | ||
channel = "CC" |
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
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
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
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,47 @@ | ||
use log::debug; | ||
use reqwest::{ | ||
header::{HeaderMap, HeaderValue, CONTENT_TYPE}, | ||
multipart::Form, | ||
}; | ||
use std::{error::Error, fs::File, io::Read}; | ||
|
||
use crate::SETTINGS; | ||
|
||
pub async fn upload_image(caption: String, file_path: String) -> Result<(), Box<dyn Error>> { | ||
let url = format!( | ||
"https://api.telegram.org/bot{}/sendPhoto", | ||
SETTINGS.telegram.token | ||
); | ||
debug!("uploading {}", file_path); | ||
let mut file = File::open(file_path)?; | ||
let mut contents = vec![]; | ||
file.read_to_end(&mut contents)?; | ||
|
||
let client = reqwest::Client::new(); | ||
let part = reqwest::multipart::Part::bytes(contents).file_name("filename.filetype"); | ||
let form = Form::new() | ||
.text("chat_id", SETTINGS.telegram.clone().channel) | ||
.text("caption", caption) | ||
.part("photo", part); | ||
|
||
let mut headers: HeaderMap = HeaderMap::new(); | ||
headers.insert( | ||
CONTENT_TYPE, | ||
HeaderValue::from_static("multipart/form-data"), | ||
); | ||
|
||
let response = client | ||
.post(&url) | ||
.headers(headers.clone()) | ||
.multipart(form) | ||
.send() | ||
.await?; | ||
if response.status().is_success() { | ||
Ok(()) | ||
} else { | ||
Err(Box::new(std::io::Error::new( | ||
std::io::ErrorKind::Other, | ||
format!("failed to upload picture: {}", response.status()), | ||
))) | ||
} | ||
} |