Trying to run Raspberry Pi camera via SSH in remote Windows desktop - python

I'm trying to edit my raspberry program files from network via SSH. For trial and error, I had to look at how the camera is going (seeing video lives, editing the picture quality, maybe adding image recognition in the future). The program can't run from the SSH, at least the part that requires "camera view" to open usually in Linux desktop.
Is there any way to do this correctly? I know Raspberry Pi camera library ran on SystemX, as so the GUI library Tkinter, maybe there's a way to cross this somehow to .NET windows GUI?
edit 1: I use Raspbian OS 32 bit for the OS. I use picamera library. If it helps, there's an error says "PiCameraMMALError...:failed to create MMAL component..:out of memory." I tried connecting to SSH via Windows Powershell and Linux subsystem, both gave me same errors.
edit 2: adding error image, might be useful.
I wonder if there's some mechanism which requires Pi to be connected to monitor to display the camera directly? Or maybe data bandwidth problem? Or just SystemX incompability on ssh hosts?
edit[3]: Adding code snippets to make error checking easier. The code is mostly still just activating camera functions
import tkinter as tk
from picamera import PiCamera
from time import sleep
#camera initiation
camera = PiCamera()
camera.rotation = 180
camera.resolution = (1080, 1080)
#camera start
def cameraStart():
camera.start_preview()
camera.preview_fullscreen = False
camera.preview_window = (0, 0, 650, 480)
#camera stop
def cameraStop():
camera.stop_preview()
#main function:
def main():
while True:
cameraStart()
print("Menu\n")
print(1. Turn off camera")
choice = input("Enter the menu:")
if choice == 1:
cameraStop()
exit()
if __name__ == "__main__":
main()
edit 4: The camera now can works fine without monitor, looks like I misplaced the port before. Thanks to #marksetchell. Now the only problem is to output the camera to windows that ran the ssh. Can it sends the output through my Windows laptop?

Related

Issue with running See3Cam via pycharm

So the code works but when the screen pops up it's all black. Can't see any images. I thought my code wasn't picking up the camera but when i ran the external application for the camera (while the code was still running) it said the camera is being used somewhere else (assuming its PyCharm because when I stop the code it works on the external application).
I also tried running the cameras external application prior to running the code but when i do that the code gives me errors. I also tried running the code without the camera plugged in but gives me an error. So I'm assuming it picks up the camera but cant give me an output.
import cv2
print("done")
cap = cv2.VideoCapture(0)
if not(cap.isOpened()):
print("cant open")
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
while(True):
ret,frame=cap.read()
cv2.imshow('preview',frame)
if cv2.waitKey(1)& 0xFF==ord('d'):
break
cap.release()
cv2.destroyAllWindows()
So, it is possible that there is an error in your code, but I think, it's more likely that PyCharm has not got the permission to use your Camera. Try to open cmd(look in the search bar, it's preinstalled) and open it as Administrator. I'm sorry that I can't test it, but I don't have a webcam in my computer.

Raspberry Pi Camera Module.Check if connected

I'm programming a small application in python for the raspberry pi 3. The application uses the camera module.
I want to check if the camera is connected to the raspberry pi. The only way i found so far of doing just that is like this:
from picamera import PiCamera
try:
piCamera = PiCamera()
except Exception as e:
print("camera is not conencted")
While this works. I don't like this because if the camera is connected i'm suddenly using its resources and creating a piCamera object where i might not need it.
So my question is. Is there any better way of doing this? Something that just checks if the camera is connected.

opencv python camera permission issue on Windows 10

While running a simple opencv video capture script, i am getting False as the result. I suspect it is due to some security setting in Windows 10 which is not allowing camera access. I checked Privacy > Camera settings, but there was no option to allow a script to access the camera. I can see that the camera is not turned on when running the following opencv based test script.
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
print(ret)
The Key to the answer is "Give time for Microsoft Windows to initalize WebCAM"
import time
capWebcam = cv2.VideoCapture(0)
time.sleep(1.000) # Make sure, you need to give time
# for MS Windows to initialize Camera
It's called "Allow access to classic application" or "Desktop applications" something like this in the bottom of the setting page, under Windows Store type applications.
This gain camera access to all EXE and DLL standalone applications.
One setting for all of them.
More info on exceptions here https://support.microsoft.com/en-us/help/4468234/windows-10-desktop-apps-and-privacy
Works for me in
'cv2.__version__ 4.2.0'
just installed latest opencv and python8 on latest windows10.
As suggested in previous helpful answers, after checking windows camera security setting, adding time delay, and running windows camera app, the program works fine.

How to stop SimpleCV camera stream?

I'm trying to learn SimpleCV using Python 2.7 in IDLE.
Once the camera form SimpleCV is initialized the camera become unavailable to other programs like native webcam application or skype etc.
from SimpleCV import *
camera = Camera()
After restarting the pc or logoff and logon the webcam becomes to those applications. It seems that even closing out from python IDLE, it doesn't close the camera stream. Is there any way to stop the camera stream of simplecv?
I couldn't replicate your issue, but if the webcam is still running even after your program terminates/you close IDLE, you can end the camera by going into task manager and killing all running Python processes.
After some experimenting, I found that if you want to accomplish the same thing directly inside the code, you could try simply deleting the reference altogether:
>>> import SimpleCV as scv
>>> cam = scv.Camera()
>>> del cam
Calling del cam caused the webcam indicator light on my laptop to turn off. Granted, this appears to be an undocumented (??) solution, so I'm not sure how robust it is. I would probably try testing this on several different laptops/webcams first, to make sure it works reliably and consistently.

v4l2 / streamer unstable in operation

I am making an online webcam for my parents, using raspberry pi. I want it to capture a photo, upload it to a webserver, then upload a copy to a different server for archiving. I use the script streamer to snap a still from the webcam. It works, the problem is that it seems that streamer sometimes crashes, looping the error message "v4l2: oops: select timeout". This can happen after a few shots, or after 10 minutes of operation, it seems random. I have added a command that kills the streamer process after each snapshot, it did make the program a bit more stable, but eventually it still gets stuck in the error loop. I don't know what the problem is or even how to debug it.. What can I do?
I am using raspbian with the included drivers. The webcam is logitech c200. I first tried using opencv to capture stills, but couldn't get it to work properly. If someone could help with that maybe it would fix the problem, I don't know..
This is the code, it's python:
import time
import sys
from subprocess import call
import ftputil
while True:
call("streamer -q -f jpeg -s 640x480 -o ./current.jpeg", shell=True)
time.sleep(0.2);
call("killall -q streamer", shell=True)
filename = str(time.time()) + ".jpg"
host = ftputil.FTPHost(*****)
#host.remove("/domains/***/public_html/webcam.jpg")
host.upload("./current.jpeg", "/domains/***/public_html/webcam.jpg", mode='b')
host.close()
host = ftputil.FTPHost(****)
#host.remove("/domains/***/public_html/webcam.jpg")
host.upload("./current.jpeg", "/webcamarchive/"+filename, mode='b')
host.close()
time.sleep(10);
Never mind, used pygame instead:
cam = pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
image = cam.get_image()

Categories