我在 jetson nano 上使用树莓派相机 v2。使用带有 python 的 gstreamer 可以正常工作,但尝试通过 javascrip 运行它是行不通的。
这是我的一些方法:
方法一:
带导航器:
<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>
回应:
(index):1 Uncaught (in promise) DOMException: Requested device not found
方法 2:
使用: 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>
未捕获的 ReferenceError:未定义要求
方法 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>
错误:
未捕获的类型错误:无法解析模块说明符“pi-camera-connect”。
有人用javascript在jetson nano上成功运行树莓派相机吗?
这种python方法虽然工作正常:
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()