5

Im using raspberry pi camera v2 on jetson nano. It works fine using gstreamer with python but trying to run it through javascrip wont work.

This is some of my approaches:

APPROACH 1:

With navigator:

<body>
    <div id="container">
        <video autoplay="true" id="videoElement"></video>
    </div>
    <!--<script type="module" src="./picam.js"></script>-->
    <script>
        var video = document.querySelector("#videoElement");

        if (navigator.mediaDevices.getUserMedia) {
            navigator.mediaDevices.getUserMedia({ video: true })
                .then(function (stream) {
                    video.srcObject = stream;
                })
        }
    </script>
</body>

With response:

(index):1 Uncaught (in promise) DOMException: Requested device not found

APPROACH 2:

Using: https://www.npmjs.com/package/pi-camera-connect

<body>
    <div id="container">
        <video autoplay="true" id="videoElement"></video>
    </div>
    <script>
        const { StreamCamera, Codec } = require("pi-camera-connect");
        const streamCamera = new StreamCamera({
            codec: Codec.H264
        });
        const writeStream = fs.createWriteStream("video-stream.h264");
        const videoStream = streamCamera.createStream();
        videoStream.pipe(writeStream);
        streamCamera.startCapture().then(() => {
            setTimeout(() => streamCamera.stopCapture(), 5000);
        }); </script>
</body>

</html>

Uncaught ReferenceError: require is not defined

APPROACH 3:

<body>
    <div id="container">
        <video autoplay="true" id="videoElement"></video>
    </div>
    <script type="module">
        import { StreamCamera, Codec } from "pi-camera-connect";
        import * as fs from "fs";

        // Capture 5 seconds of H264 video and save to disk
        const runApp = async () => {
            const streamCamera = new StreamCamera({
                codec: Codec.H264
            });

            const videoStream = streamCamera.createStream();
            const writeStream = fs.createWriteStream("video-stream.h264");
            videoStream.pipe(writeStream);

            await streamCamera.startCapture();
            await new Promise(resolve => setTimeout(() => resolve(), 5000));
            await streamCamera.stopCapture();
        };

        runApp();
    </script>
</body>

Error:

Uncaught TypeError: Failed to resolve module specifier "pi-camera-connect".

Anyone successfully run raspberry pi camera on jetson nano with javascript?

This python approach works fine though:

import cv2
print(cv2.__version__)
dispW=640
dispH=480
flip=2
camSet='nvarguscamerasrc !  video/x-raw(memory:NVMM), width=3264, height=2464, format=NV12, framerate=21/1 ! nvvidconv flip-method='+str(flip)+' ! video/x-raw, width='+str(dispW)+', height='+str(dispH)+', format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink'
cam= cv2.VideoCapture(camSet)

while True:
    ret, frame = cam.read()
    cv2.imshow('nanoCam',frame)
    if cv2.waitKey(1)==ord('q'):
        break
cam.release()
cv2.destroyAllWindows()
acroscene
  • 845
  • 4
  • 16
  • 45
  • You seem to be trying to run node.js code in a browser. That won't work, since nodejs is a server application. `require` not found shows that you are running in an environment that doesn't contain nodejs. What exactly are you trying to do? Are you trying to a) connect to a jetson on the network through a webserver and see pi camera images? or b) See a camera feed from the browser that is running on the jetson? – Karthik Sriram Mar 24 '21 at 05:59
  • Im running the code with live-server. No, I am simply trying to use raspberry pi camera instead of ordinary webcam in a video-element – acroscene Mar 25 '21 at 12:04

0 Answers0