unosquare / raspberryio

The Raspberry Pi's IO Functionality in an easy-to-use API for Mono/.NET/C#
https://unosquare.github.io/raspberryio
Other
672 stars 104 forks source link

CaptureImageJpeg No Such File or Directory #208

Closed thnk2wn closed 4 years ago

thnk2wn commented 4 years ago

Describe the bug Using Pi.Init<BootstrapWiringPi>(); followed by byte[] imageBytes = Pi.Camera.CaptureImageJpeg(1024, 768); and I get the following error:

02:14:36 ERR] Error taking picture
System.ComponentModel.Win32Exception (2): No such file or directory
   at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at Swan.ProcessRunner.<>c__DisplayClass7_0.b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__274_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location where exception was thrown ---
   at Unosquare.RaspberryIO.Camera.CameraController.CaptureImageAsync(CameraStillSettings settings, CancellationToken ct)
   at Unosquare.RaspberryIO.Camera.CameraController.CaptureImageJpeg(Int32 width, Int32 height)

To Reproduce Steps to reproduce the behavior:

  1. Match environment details as shown in the Devices section.
  2. Run code as listed in above description

Expected behavior Picture bytes to be obtained.

Screenshots If applicable, add screenshots to help explain your problem.

Devices

Additional context The camera is enabled and I was able to test it via raspistill -o image.jpg. Is there something else I have to install or configure on the device to use this? Ideas?

thnk2wn commented 4 years ago

I'm assuming I need to adjust the creation of my container with potential volume mounts or Dockerfile steps like:

RUN apt-get install libraspberrypi-bin -y
RUN usermod -a -G video root

Not sure what all dependencies this library has for the camera in terms of file / directory access, permissions etc. to account for when running containerized but I can look at the source. From the error though it looks like it's just shelling out to another process rather than a direct embedded library calls so maybe going through Unosquare just for this one camera method call is overkill.

thnk2wn commented 4 years ago

It appeared to be just shelling to raspistill so I was able to make it work by adding ENV PATH="/opt/vc/bin:${PATH}" to the Dockerfile and adding -v /opt/vc/bin:/opt/vc/bin to docker run.

The complete docker run looks like below.

docker run \
    --privileged \
    -v /opt/vc/lib:/opt/vc/lib \
    -v /opt/vc/bin:/opt/vc/bin \
    -v /home/pi/camera-output:/home/pi/camera-output \
    -d \
    --name $name \
    $username/$name:latest