Code Monkey home page Code Monkey logo

homesecurity's Introduction

Introduction

Software for security monitoring with single or multiple cameras with:

  • Raspberry pi zero
  • Raspberry pi 3B/4B
  • Jetson Nano
  • Jetson TX2
  • Jetson AGX Xavier

Functions

  • Raspberry pi 3: The camera performs motion detection and records a video. The video is sent in an email.
  • Jetson Nano: After recording video, an object detection model checks if a person is presentin the video. If yes, the video and a screenshot are sent by email.
  • Jetson TX2 + Pi Zeros: A set of 4 raspi zeros stream video over Wi-Fi to a Jetson TX2, which combines inputs from all sources, performs object detection and displays the results on a monitor.
  • Jetson Xavier + Pi Zeros: Same as that of TX2

Configurations

Raspberry Pi 3

Architecture 1

Jetson Nano

Architecture 2

Raspberry Pi Zero W + Jetson TX2

Architecture 3

Raspberry Pi Zero W + Jetson Xavier

Architecture 4

Setup

Clone the repo and choose the device by modifying the DEVICE variable in the launch.sh script.

git clone http://www.github.com/dataplayer12/homesecurity.git
cd ./homesecurity
nano launch.sh #Edit the DEVICE variable to be one of the four options described in the comments
bash launch.sh

You may have to install some dependecies in order for the script to work. Instructions for dependencies for each device are in their respective directories:

If you are using a raspberry pi 3/4 or Jetson Nano, you will have to provide email addresses for receiving videos when some activity is observed by the camera. This is done by writing these details to a confidential.txt text file.

cd homesecurity #be in the base directory of the project
nano confidential.txt #open text file

The contents of confidential.txt are as follows:

{"recepients": ["email1", "email2"], "myemail": "senderemail", "mypass": "senderpassword"}

You will have to configure the senderemail to allow login from your pi. For Gmail, you can do this by enabling two-factor authentication and setting an app-specific password for your gmail account or by downgrading your security settings to allow less secure devices like the pi to access your Google account. No special settings are required on the receiver's email address. The confidential.txt file will never be tracked or uploaded to your GitHub repo if you are forking the project and developing it further. Please raise an issue if you have any specific questions.

Note on network latency on TX2 and Xavier:

In this application, the performance of the jetson is limited by the bandwidth of your local network (not to be confused with neural network ;) ). The 4 IP cameras as well as the jetson may all be on Wi-Fi, and all the activity can be challenging for a router to keep up with. Moreover, since the raspberry pi zeros support only 802.11 b/g/n standards (2.4 GHz band), their latency is higher than 5 GHz bands supported by default antenna on the jetson's carrier board.

If you see many "Cannot read camera at.." messages, you have a few options:

  • If you have opened a camera stream on a browser, please close it as streaming to the browser doubles the work the pi has to do.
  • Try increasing qsize in jetsontx2/tx2_config.py or xavier/xavier_config.py. This will reduce the frequency of these messages, but will result in higher lag between the screen and camera. If the lag becomes too much, reduce qsize and try next option.
  • Try setting threaded = False in the same file. This will get rid of the benefits of multi-threading and read all cameras in series from the same thread. It will reduce the display fps by ~2 on TX2, but will get rid of ugly error screens.
  • Try connecting the jetson to the network via ethernet and if possible the pi zeros as well. If you must keep the jetson on Wi-Fi, please use a router that supports 5 GHz band (802.11 ac in marketing speak).

Development

This software was written for monitoring the security of my home with a raspberry pi. The section related to raspberry pi 3 has been in use at my home for about two years and there are failsafes built in to prevent issues such as loss of network connection and memory overflow. Since my requirements are well-served with the current version, more features will be added only if requests are made by raising issues. Pull requests which add useful features or failsafes are more than welcome!

homesecurity's People

Contributors

bdherouville avatar dataplayer12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

homesecurity's Issues

Running launch.sh and returning errors in logs

I have been installing and updating dependencies on my rasberry pi, when I run the project ($ ./launch.sh), I get the following messages in the log file. Can you please share ideas on how to resolve? Thanks in advance

`2020-11-28 20:46:43.196164: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory

Traceback (most recent call last):

File "raspi3/securitycam.py", line 10, in
from file_manager import FileManagerThread, FileCleanerThread, counter

File "/home/pi/projects/homesecurity/raspi3/file_manager.py", line 6, in
import human_detect as hd

File "/home/pi/projects/homesecurity/raspi3/human_detect.py", line 62, in
odapi = DetectorAPI(path_to_ckpt=model_path)

File "/home/pi/projects/homesecurity/raspi3/human_detect.py", line 18, in init
serialized_graph = fid.read()

File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/lib/io/file_io.py", line 122, in read
self._preread_check()

File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/lib/io/file_io.py", line 84, in _preread_check
compat.as_bytes(self.__name), 1024 * 512)
tensorflow.python.framework.errors_impl.NotFoundError: ssd_mobilenet_v1_coco_2017_11_17/frozen_inference_graph.pb; No such file or directory`

Please Add instructions for compiling SSD Mobilenet

It is expected that your Jetson TX2 already has numpy and opencv installed. Install the official tensorflow release for Jetson TX2 by following the instructions from here. You may also have to compile the MobileNet SSD model for your version of tensorflow and JetPack.

//TODO: Add instructions for compiling SSD Mobilenet

Disable cameras on demand

Would like to be able to disable 1 or more of the 4 cameras on demand. Sometimes cameras don't come in groups of 4. Would be nice to comment out one of the URL's and have it ignore that camera.

Extracting bounding box coordinates

When the program determines an object, confidence and then box location it can print this.

[67] [0.48267296] [[361 4 715 937]]

I need to extract the 361 and 4 to help determine which of the 4 boxes it is in. Any ideas on how this could be achieved? I've cheated a bit with the confidence by using any or all on my if statement, but I can't do that with the box.

Saving Images

I've been messing around with this function for the tx2 branch. I'd like it to save a screenshot of the image when it detects a person. I've tried a few methods and failed.

I did notice that the window has a built in save UI. I've tried using a keyboard function to open and save, but it's clumsy and doesn't always work.

Can that save function be called via script and better yet use a timestamp?

ModuleNotFoundError: No module named 'tensorflow.contrib'

Hello
I keep getting following error.
Any help would be appreciated.
Thanks

jetson@chung-jetson:/media/jetson/EXTDR/homesecurity$ python3 jetsontx2/compile_ssd_mobilenet.py
2020-09-09 12:52:44.261984: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.2
Traceback (most recent call last):
File "jetsontx2/compile_ssd_mobilenet.py", line 1, in
import tensorflow.contrib.tensorrt as trt
ModuleNotFoundError: No module named 'tensorflow.contrib'

Change from person detection to car detection

Would changing line 33 of human_detect.py from detection_classes:0 to detection_classes:2 detect cars instead of people? Thank you.

COCO Classes
1 | person | person | person | person
2 | bicycle | bicycle | bicycle | vehicle
3 | car | car | car | vehicle

Tensorflow Model issue

Ran the launch bash, got this.

File "jetsontx2/tx2_surveillance.py", line 150, in
main()
File "jetsontx2/tx2_surveillance.py", line 125, in main
trt_graph = load_trt_pb(pb_path)
File "/home/vondalej/homesecurity/jetsontx2/utils/od_utils.py", line 28, in load_trt_pb
trt_graph_def.ParseFromString(pf.read())
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/lib/io/file_io.py", line 122, in read
self._preread_check()
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/lib/io/file_io.py", line 84, in _preread_check
compat.as_bytes(self.__name), 1024 * 512)
tensorflow.python.framework.errors_impl.NotFoundError: ./human_detection/ssd_mobilenet_v1_coco_trt.pb; No such file or directory
FATAL: exception not rethrown

Noticed that there is another script to run to compile it. When I ran that I got this...

Traceback (most recent call last):
File "jetsontx2/compile_ssd_mobilenet.py", line 2, in
from tf_trt_models.detection import build_detection_graph
ModuleNotFoundError: No module named 'tf_trt_models'

tx2_surveillance.py core dumped

Not even sure where the error is in here. I will say the process took all 4GB of RAM and 6 Gigs of swap while running.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "jetsontx2/tx2_surveillance.py", line 150, in
main()
File "jetsontx2/tx2_surveillance.py", line 135, in main
, , _ = detect(dummy_img, tf_sess, conf_th=.3, od_type=od_type)
File "/home/vondalej/homesecurity/jetsontx2/utils/od_utils.py", line 87, in detect
feed_dict={tf_input: img[None, ...]})
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py", line 956, in run
run_metadata_ptr)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py", line 1180, in run
feed_dict_tensor, options, run_metadata)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py", line 1359, in do_run
run_metadata)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/client/session.py", line 1384, in do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation Postprocessor/BatchMultiClassNonMaxSuppression/TRTEngineOp_1: Could not satisfy explicit device specification '/device:CPU:0' because no supported kernel for CPU devices is available.
Colocation Debug Info:
Colocation group had the following types and supported devices:
Root Member(assigned_device_name_index
=-1 requested_device_name
='/device:CPU:0' assigned_device_name
='' resource_device_name
='' supported_device_types
=[GPU] possible_devices_=[]
TRTEngineOp: GPU

Colocation members, user-requested devices, and framework assigned devices, if any:
Postprocessor/BatchMultiClassNonMaxSuppression/TRTEngineOp_1 (TRTEngineOp) /device:CPU:0

Op: TRTEngineOp
Node attrs: use_calibration=false, fixed_input_size=true, input_shapes=[], OutT=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], precision_mode="FP16", static_engine=true, serialized_segment="ptrta\000...00\000\000", cached_engine_batches=[], InT=[DT_FLOAT], calibration_data="", output_shapes=[], workspace_size_bytes=7965653, max_cached_engines_count=1, segment_func=Postprocessor/BatchMultiClassNonMaxSuppression/TRTEngineOp_1_native_segment[], segment_funcdef_name=""
Registered kernels:
device='GPU'

 [[node Postprocessor/BatchMultiClassNonMaxSuppression/TRTEngineOp_1 (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py:1748) ]]

Original stack trace for 'Postprocessor/BatchMultiClassNonMaxSuppression/TRTEngineOp_1':
File "jetsontx2/tx2_surveillance.py", line 150, in
main()
File "jetsontx2/tx2_surveillance.py", line 125, in main
trt_graph = load_trt_pb(pb_path)
File "/home/vondalej/homesecurity/jetsontx2/utils/od_utils.py", line 38, in load_trt_pb
tf.import_graph_def(trt_graph_def, name='')
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/util/deprecation.py", line 513, in new_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/importer.py", line 405, in import_graph_def
producer_op_list=producer_op_list)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/importer.py", line 517, in _import_graph_def_internal
_ProcessNewOps(graph)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/importer.py", line 243, in _ProcessNewOps
for new_op in graph._add_new_tf_operations(compute_devices=False): # pylint: disable=protected-access
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 3561, in _add_new_tf_operations
for c_op in c_api_util.new_tf_operations(self)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 3561, in
for c_op in c_api_util.new_tf_operations(self)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 3451, in _create_op_from_tf_operation
ret = Operation(c_op, self)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py", line 1748, in init
self._traceback = tf_stack.extract_stack()

terminate called without an active exception
terminate called recursively
./launch.sh: line 43: 18873 Aborted (core dumped) python3 jetsontx2/tx2_surveillance.py

change from h264 to h265

Hello sir,
Can I do it with jetson orin nano instead of jetson nano?
Does this project use h264 encoding video to stream, if so, if I want to change from h264 to h265, how can I do it?
Thank you sir.
Have a good day,

Understand your code.

Hello,

I was reading about your project which I really like, I am a computer science student and I enjoy creating things with IoT devices especially the Pi, however I never used the Jetson before or anything related to neural network or machine learning. I feel like your project would help me learn how I can use that, I would appreciate if you can get me up to speed on your files structure so I understand what each file does and if you can provide me with some comments, that would be so much appreciated

IP cameras instead of pi's?

Are you able to use existing IP cameras instead of the RPI setup? Also where is the setup details for the Jetson TX2 i.e where do I specify the IP addresses of the cameras?

TensorFlow Error

Hi, thanks for the great work!
Any idea why this error occurred? (i had installed tensorflow)
hserror

Missing tensorflow file

Looks like the model is missing.

File "jetsontx2/tx2_surveillance.py", line 150, in
main()
File "jetsontx2/tx2_surveillance.py", line 125, in main
trt_graph = load_trt_pb(pb_path)
File "/home/vondalej/homesecurity/jetsontx2/utils/od_utils.py", line 28, in load_trt_pb
trt_graph_def.ParseFromString(pf.read())
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/lib/io/file_io.py", line 122, in read
self._preread_check()
File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/lib/io/file_io.py", line 84, in _preread_check
compat.as_bytes(self.__name), 1024 * 512)
tensorflow.python.framework.errors_impl.NotFoundError: ./human_detection/ssd_mobilenet_v1_coco_trt.pb; No such file or directory
FATAL: exception not rethrown

Opencv4.5.0

Hi, I was thinking to use OpenCV 4.5.0 on both pi and jetson, what do you suggest? have you tried it?

Tf error

~/homesecurity$ bash launch.sh bash: launch.sh#!/bin/bash: No such file or directory Traceback (most recent call last): File "jetsonano/securitycamnano.py", line 11, in from file_managernano import FileManagerThread, FileCleanerThread, counter File "/home/flaryx32/homesecurity/jetsonano/file_managernano.py", line 6, in import human_detect as hd File "/home/flaryx32/homesecurity/human_detection/human_detect.py", line 63, in odapi = DetectorAPI(path_to_ckpt=model_path) File "/home/flaryx32/homesecurity/human_detection/human_detect.py", line 17, in init od_graph_def = tf.GraphDef() AttributeError: module 'tensorflow' has no attribute 'GraphDef'

Which JetPack Version for Xavier

Hi. I am running JetPack version 4.2.1 on my Xavier. When I run launch.sh, xavier_surveillance.py fails on multiple libraries as they are too new plus the CUDA is not 10.0. What JetPack load did you successfully test with? TIA.

Failed library versions:

  • libopencv_highgui
  • libopencv_videoio
  • libopencv_imgcodecs
  • libopencv_imgproc
  • libopencv_imgcodecs
  • libopencv_imgproc
  • libopencv_core
  • libcudart
  • libcublas
  • libcurand
  • libcudnn

Renamed the libraries for fun and received a core dump.

Which JetPack and TF Version?

Hi. Great project. As I work through errors running on Nano withJetPack 4.3, I am finding that your project requires tensorflow<2 and CUDA=10.0. Is that correct? Which JetPack version and TF version did you use successfully with your project? TIA.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.