Giter Site home page Giter Site logo

webcam's Introduction

README.md

This project demos the camera video streaming from nvidia jetson nano/nx

keywords: nvidia nano; tensorrt; camera video streaming; yolov4; flask; jwt autentication

This project runs in jetson nano/xavier nx device with jetpack 4.5.1 and CSI camera installed. The camera captured video is sent to tensorrt version of yolov4 model, the output video is then streamed by flask.

you can watch the model's output video from: http://your_ip_addr:8000/start. the url is protected with jwt autentication. The authorized user can be created in users table in sqlite3 database users.db(see source code for table schema).

build yolov4 model for tensorrt

download yolov4 pre-trained model yolov4.weights, renname to yolov4-416.weights and put it in yolo directory of this project, convert it to onnx format:

# from yolo directory:
python3 yolo_to_onnx.py -m yolov4-416

then convert the onnx format to tensorrt format:

python3 onnx_to_tensorrt.py -v -m yolov4-416

the generated model is yolov4-416.trt(in yolo directory)

flask jwt authentication

in flask, a route is protected by authentication with:

@app.route("/")
@token_required

where:

app.config['SECRET_KEY']='YOUR_SECRET_KEY_HERE'
app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///./users.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

def token_required(f):  
   @wraps(f)  
   def decorator(*args, **kwargs):
      # havent login 
      try:
         token = session["token"]
      except:
         return render_template('login.html')
      if 'x-access-tokens' in request.headers:  
         token = request.headers['x-access-tokens'] 

      if not token:
         #return jsonify({'message': 'a valid token is missing'})   
         return render_template('login.html')

      try: 
         data = jwt.decode(token, app.config['SECRET_KEY'])
         current_user = Users.query.filter_by(public_id=data['public_id']).first()  
      except Exception as e:
         print(f'exception message={str(e)}', file=sys.stdout)
         return render_template('login.html')

      return f(current_user, *args,  **kwargs)  
   return decorator 

If unthorized user access route /, then will be redirected to login.html, after successful authentication, the access token is stored in session for later use.

In /login method, the username/password taken from form data are compared with the encoded name/password in table users.

add user for jwt authentication

run add_user.py to add authorized user for authentication, you can specify the 'SECRET_KEY', remember also modify the corresponding value in yolo_stream.py too.

webcam's People

Contributors

pzs7602 avatar

Watchers

 avatar

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.