I have set up an ssh connection between tx1 and my laptop and I am trying to run an opencv code from my laptop that is in the ubuntu server (tx1). This is the code I have used:
from flask import Flask, render_template, request
import paramiko
import time
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/execute_opencv', methods=['POST'])
def execute_opencv():
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('<tx1-ip>', username='ubuntu', password='<*******>')
stdin, stdout, stderr = ssh.exec_command('python /home/ubuntu/Desktop/<my-app>.py')
#time.sleep(3)
output = stdout.read()
ssh.close()
print("Output from SSH command:", output)
return f"OpenCV code executed: {output}"
if __name__ == '__main__':
app.run(debug=True)
Opencv code is in tx1 which is just a simple script that starts the video feed and saves the file in a folder in the ubuntu desktop. When I run the code in ubuntu it executes perfectly but when I try to run the code from my laptop through this flask app it doesn’t execute. It seems to execute every line before import cv2 (I added print statements to see if it shows an output on the webpage of my laptop and it prints all the statement before import cv2). How do I solve this?
I wrote a simple python script on the tx1 to print the current working directory and that seems to execute perfectly. It is only that import cv2 is not working.
I am very new at this so please any kind of help is appreciated!!