sending image from the raspberry pi to discord

April 4, 2024, 06:04

jacked_ripper

Completely new to this. I got raspberry pi4 and I am trying to setup a security system that will send me pictures when the camera recognizes a face. I just started working on this. I heard we hooks on discord can be used to send a message from the pi to the app. How do I even begin with all this

oops.se

I would start to search for "discord api post pictures" and then you will likely find answers like: https://stackoverflow.com/questions/68499998/how-can-i-send-a-picture-with-the-discord-api-and-python-requests

k9t33n

i know how to use webhooks

k9t33n

they are pretty nice. and im assuming you haven't figured out the recognizing face part

jacked_ripper

Yes I am totally new to all this

jacked_ripper

I just did the pi' set up and started so a complete newbie yes

jacked_ripper

I'll read this right now thanks

oops.se

Then I wish you welcome to the land of Pi

jacked_ripper

Thanks a lot

k9t33n

here
py
from discord_webhook import DiscordWebhook

message = str(input("what do you want to send? : "))
webhook = DiscordWebhook(url="[webhook url]", content=message)
response = webhook.execute()
this is from my own tiny project

jacked_ripper

Can you walk me through this a bit

k9t33n

Sure

k9t33n

You need your own discord server your a admin on

jacked_ripper

Ok

k9t33n

Then in settings click on webhook and create webhook

k9t33n

Name it and select a channel. Then paste in the URL where I put [webhook URL] in the code

k9t33n

And after you run pip install discord you can run that code on your pi

jacked_ripper

Ok I will try it

jacked_ripper

I am doing the entire set up as we speak

k9t33n

Ok

jacked_ripper

It looks wonky ngl I am trying to figure out how to use my pi4 while connecting it to my main pc

k9t33n

You'd use ssh

jacked_ripper

Does it allow access to the graphical interface?

k9t33n

No ssh is strictly cli

k9t33n

VNC is for gui

jacked_ripper

I will look into both then I'll come back with more

k9t33n

I can guide you through it once you got your pi booting

jacked_ripper

It's done

jacked_ripper

Updates and all

jacked_ripper

Got the fisherman desktop

jacked_ripper

🙂 nice

k9t33n

Yup

k9t33n

So this is with a display?

jacked_ripper

Yes

k9t33n

Ok run sudo raspi-config in a terminal

jacked_ripper

Ok

jacked_ripper

Done

k9t33n

And go to interfaces

jacked_ripper

Ok

k9t33n

Then ssh and make sure it's on

k9t33n

And then vnc and make sure it's on

k9t33n

Use arrow keys and enter to do that

k9t33n

And then back and finally finish

jacked_ripper

Both are enabled

jacked_ripper

Done

k9t33n

Great

k9t33n

And check in the corner is the WiFi symbol like two way arrows?

k9t33n

Or is there a cross in one of them

k9t33n

Top right corner

jacked_ripper

There is nothing like that

jacked_ripper

It's just regular wifi icon

jacked_ripper


jacked_ripper

Main reason is wonky display and setup

jacked_ripper

That is why I want to use my pc

jacked_ripper

Fixed screen issue still no arrows

k9t33n

oh yeah

k9t33n

sorry im used to ethernet

k9t33n

your sorted then

k9t33n

ill be back w u

jacked_ripper

Ok ok

k9t33n

okay

k9t33n

so in your pc press the home button and type cmd

k9t33n

then press the first option to open up your terminal

k9t33n

and type ssh [pi username]@[pi ip]

jacked_ripper

I need to remove it from the pi then

k9t33n

what?

jacked_ripper

Got one keyboard

k9t33n

oh ok

jacked_ripper

Pi IP do I need the pi's up address first?

k9t33n

yeah sorry. in the pi just hover above the wifi with your mouse

jacked_ripper

I got the pi IP and it's mac

k9t33n

okay great

jacked_ripper

Do I need to download any thing to my pc to get the pi gui?

k9t33n

yes you do. you need to download vnc veiwer

k9t33n

does ssh work?

jacked_ripper

Gonna try now

k9t33n

ok

jacked_ripper

Doesn't work

jacked_ripper

Not internal or external command

jacked_ripper

Something about fingerprints now

jacked_ripper

Ok ok

jacked_ripper

I am connected

jacked_ripper

Vnc working fine a bit slow idk why

jacked_ripper

On desktop end

k9t33n

Yeah that's most likely because of WiFi speed

k9t33n

You have an ethernet cable?

jacked_ripper

Yeah

starsalt

There's also an option of using Node-red + discord contrib + maybe tensor flow stuff for facial recog (the latter you'll have to study yourself, but the discord part i can maybe help walk you through?) https://flows.nodered.org/node/node-red-contrib-discord-advanced

starsalt

you just have to pass it(the image) as Base64

starsalt

the flow would look similar to this: just replacing the triangle with the facial recognition stuff that you want to put in

starsalt

also there's example's on the author's repo on formatting in order to upload attachments https://github.com/Markoudstaal/node-red-contrib-discord-advanced/wiki/Examples#attach-an-array-of-attachments

jacked_ripper

i ran into an issue it doesn't find the camera

jacked_ripper

not sure why

starsalt

are the ribbons properly connected?

starsalt

like not backwards

jacked_ripper

i believe so

starsalt

try vcgencmd get_camera

jacked_ripper

0

jacked_ripper

all of it

starsalt

oh then it's not getting detected

starsalt

maybe
sudo raspi-config 
and check if it's enabled?

jacked_ripper

not found

starsalt

oh then idk sorry hehe

jacked_ripper

it's - not _

jacked_ripper


jacked_ripper

i don't even have the camera option to enable it

k9t33n

That's not in the current update

k9t33n

It used to be but you don't need to anymore

k9t33n

<@730090369244725259> run libcamera-hello

starsalt

oop mb hehe im still on lower ver

jacked_ripper

IT WORKED

jacked_ripper

took a snap

k9t33n

Yes do a dist upgrade

k9t33n

Great

starsalt

yuusss next month XD too swaaaaamped

jacked_ripper

can't find the pick tho

jacked_ripper

pic*

k9t33n

You can run libcamera-hello -t -0 to run it infinitely

k9t33n

It won't save one. This is just a test command

k9t33n

And it wasn't a pic it was a live feed

k9t33n

It may be really slow and low frame rate btw. That's because it's attempting full resolution

jacked_ripper

30 fps

jacked_ripper

smooth

k9t33n

Really?

jacked_ripper

1080p

jacked_ripper

mhm

k9t33n

It said 30fps for me but it definitely wasn't 30 fps

k9t33n

More like 15

jacked_ripper

it's 30 +

jacked_ripper

really smooth

jacked_ripper

surprising tbh

k9t33n

Okay your lucky then

k9t33n

As for the face recognition you want to do it all yourself?

k9t33n

As in you want to learn.

jacked_ripper

well we have open cv

jacked_ripper

no?

jacked_ripper

i read it can be used

jacked_ripper

ofc i want to learn

k9t33n

Yes should be

k9t33n

I meant like you could just copy some GitHub code pretty easily or you can enjoy it a little more

jacked_ripper

ofc i welcome all the help

jacked_ripper

i am reading on how to do the webhook from what saltea sent

jacked_ripper

i also got told that i can use telegram to make a bot

k9t33n

Does my code work?

jacked_ripper

which one?

starsalt

the one i sent is Node-Red based, it's block coding so it's easy to experiment hehe but if you want to refine you'll want to do K9's method to get better flexibility on what you can do

jacked_ripper

oh for the discord webhook? i didn't get to it yet

starsalt

it's pretty much the same, it uses discord.js just that the node red version is simplified and limited

jacked_ripper

could you give me a rundown of the code?

jacked_ripper

why

starsalt

nodes in node red are just generic like this does that and that does this.. erm idk how to explain but you should check the examples on the github link discord.js on the other hand is complex but you can do more cause it's wide open

starsalt

for context discord.js has this much on documentation: https://discord.js.org/docs/packages/discord.js/14.14.1

starsalt

node red version only has this much

k9t33n

You can just send a image link can't you? My codes simple to me

jacked_ripper

an image link ok but where would you host the image

k9t33n

But idk. I have worked with python for a while

starsalt

yep you can hehe although i think they want to send a file, so they'd need to send as base64, it's doable on code though

k9t33n

No need to host

k9t33n

Ah yes okay

jacked_ripper

using firebase has been suggested to me but i want to avoid all that hassle, i was thinking of installing discord on the pi at first ngl

starsalt

for code it would go: image > base 64 > send no need to host

jacked_ripper

have it send the last pic + warning message

k9t33n

Pi would do all the work

jacked_ripper

yes exactly

starsalt

alternatively you can send as link i guess and selfhost an image server maybe?

jacked_ripper

installing disc or telegram and using their bot is going to be much easier

k9t33n

I don't know how I did it but I just pasted the link in and done

jacked_ripper

my idea is Face rec > send message in server + image

k9t33n

Yes

jacked_ripper

there is also gotify

jacked_ripper

so what do you think i should do ?

starsalt

just try them all hehe and go with what works best for you

starsalt

i think it's cause of how discord handles it hehe it's possible to send as both buffer(base64) and link (the prior being for if you have the file locally)

k9t33n

Yeah makes sense

k9t33n

I forgot to mention that small project of mine was just to troll my friends so i ran the code manually instead of automatically

jacked_ripper

At part time work I'll try to do more later

k9t33n

Okay

k9t33n

Great

jacked_ripper

ok i am on gotta boot up the pi

jacked_ripper

Hello guys, i have a question i noticed that the pi's Ip changed a few times

jacked_ripper

is there a way to give it a static ip?

jacked_ripper

or should i change the hostname ?

jacked_ripper

i ran into a little issue, while installing the open cv libjasper can't be installed

jacked_ripper

ngl i am a bit lost

thunder07337

There is a lack of context. What exactly do you have in mind? What did you do/try to get this error message? Are you following instructions? If so, please post the link to the instructions here. If I ask you "why is my computer not working" you can't help me without more detailed information about what's wrong, can you?

k9t33n

Pip install? Can we have the exact error?

k9t33n

And you can just use a hostname by using
ssh [username]@[hostname].local

jacked_ripper

ill do it next, for now i am struggling with the opencv and cmake stuff

k9t33n

Sure

jacked_ripper

Errors everywhere!

thunder07337

Then please post the command you have used and the error it returns. Without that we can't help...

jacked_ripper

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ -D ENABLE_NEON=ON \ -D ENABLE_VFPV3=ON \ -D BUILD_TESTS=OFF \ -D INSTALL_PYTHON_EXAMPLES=OFF \ -D OPENCV_ENABLE_NONFREE=ON \ -D CMAKE_SHARED_LINKER_FLAGS=-latomic \ -D OPENCV_PYTHON_INSTALL_PATH=lib/python3.9/dist-packages \ -D BUILD_EXAMPLES=OFF ..

jacked_ripper

gonna focus on this for a bit

jacked_ripper

bro was typing

jacked_ripper

XDD

k9t33n

Thinkin

jacked_ripper

about?

k9t33n

Is this the error it returns? Strange error

thunder07337

This is not an error, this is the command...

k9t33n

Yeah thought so

k9t33n

Can you give us one?

jacked_ripper

i did a new install

jacked_ripper

using a code from the example to try it

jacked_ripper


jacked_ripper

gave me this

jacked_ripper

i assume it's a new command now

jacked_ripper

since the project file is years old

jacked_ripper

<@1071178789939331253>

k9t33n

Nah just run pip install picamera

jacked_ripper

i did just now

jacked_ripper

even better

jacked_ripper

non stop wtf is this

k9t33n

What?

jacked_ripper


jacked_ripper

just installed it and tried to run the code gave me this

k9t33n

Where'd you get this code from?

jacked_ripper

this one

k9t33n

Try
git clone --single-branch https://github.com/ageitgey/face_recognition.git
cd ./face_recognition/examples
python3 facerec_on_raspberry_pi.py

jacked_ripper

why??

jacked_ripper

i already have it on

jacked_ripper

i mean the code

jacked_ripper

unless you mean some specific thing

jacked_ripper

give me 5 ill try an other command, i noticed i am not using cv2

jacked_ripper

i am a total noob at python 3 so coding is hard bro

jacked_ripper

what do these commands do tho

jacked_ripper

i am on a vrtual env

jacked_ripper

won't this make a mess?

k9t33n

Already ran the command? It doesn't look like it

k9t33n

No

jacked_ripper

same error bro

jacked_ripper


jacked_ripper


jacked_ripper

efverytghing here

k9t33n

I'm trying

k9t33n

Also helping a suicidal person so dual welding so sorry for the late replys

jacked_ripper

you are already doing so much by helping me

jacked_ripper

don't worry i am patient

k9t33n

Can I answer you in the morning?

k9t33n

I'm getting about a ping every 5 seconds rn

jacked_ripper

it's ok oh and one thing i just had to retry

k9t33n

Okay

jacked_ripper

libcamera-hello

jacked_ripper

works

jacked_ripper

so it's not a cam issue

jacked_ripper

you think it's the 64bit thing?

jacked_ripper

i just read it's not handled on 64 for somereason

k9t33n

Maybe

k9t33n

Okay back

k9t33n

Have you tried 32 bit os?

jacked_ripper

no but i read that it still shows

jacked_ripper

there is a picamera2

jacked_ripper

and i have it so i will try it

jacked_ripper

i tried picam2

jacked_ripper

it works

jacked_ripper

ok the test

jacked_ripper

but now how to use it is a mystery

k9t33n

No clue

jacked_ripper

going insane slowly man

k9t33n

Welcome to Linux.

jacked_ripper

how do i use libcamera instead

jacked_ripper

should i just do a fresh install

jacked_ripper

os

jacked_ripper

i mean

k9t33n

Sure if you haven't got anything else on this one

jacked_ripper

i only have this project

jacked_ripper

i found this <@1071178789939331253>

jacked_ripper

but it sends me to to the config.txt

jacked_ripper

there i don't have the lines

jacked_ripper

unless i have to add them

jacked_ripper

gonna try to do a fresh install on 32bit and use python 3.9.2 or older if needed <@1071178789939331253> <@1187039958561726494> wish me luck guys

jacked_ripper

Good news

jacked_ripper

the setup worked

jacked_ripper

i got the pi running and using fast api got a site running streaming from the pi, local host etc

jacked_ripper

by default it's showing the pi camera

jacked_ripper

but when i try to select the camera in settings to take headshots to train the face rec model it doesn't show me the camera

jacked_ripper


jacked_ripper


jacked_ripper


jacked_ripper

but if i go to home the pi camera is streaming just fine

k9t33n

a little to many pings btw

k9t33n

i dont actually know, never seen this project before myself

k9t33n

try running the whole thing with sudo ig for permisions although i dont think thatl work

jacked_ripper

sorry i got excited

jacked_ripper

Tired 18 hours at this