Selective Camera Setup

This commit is contained in:
Steven C 2024-03-03 00:12:50 -08:00
parent 4db224bc11
commit fb19c5b218
3 changed files with 41 additions and 24 deletions

View File

@ -1,34 +1,39 @@
<script> <script>
export default { export default {
props: ['cameraNumber'],
data() { data() {
return { return {
localIp: 'http://192.168.1.173', //maybe change accordingly
port: '5000', //maybe change accordingly
cameraUrls: {
1: 'video_feed', //cam url here
2: 'video_feed2',
}
}; };
}, },
mounted() { mounted() {
this.initCam(); // this.initCam();
}, },
methods: { methods: {
async initCam() { // async initCam() {
try { // try {
const constraints = { video: true }; // const constraints = { video: true };
const stream = await navigator.mediaDevices.getUserMedia(constraints); // const stream = await navigator.mediaDevices.getUserMedia(constraints);
this.streams.push(stream); // this.streams.push(stream);
} catch (error) { // } catch (error) {
console.error('Error accessing camera:', error); // console.error('Error accessing camera:', error);
} // }
// },
getCameraImageUrl(cameraNumber) {
return `${this.localIp}:${this.port}/${this.cameraUrls[cameraNumber]}`;
} }
} }
}; };
</script> </script>
<template> <template>
<!-- <div class="app">
<div class="video-section" v-for="(stream, index) in streams" :key="index">
<video ref="videoPlayer" :srcObject="stream" controls></video>
</div>
</div> -->
<div class="box video-section"> <div class="box video-section">
<video ref="videoPlayer" :srcObject="stream" controls></video> <img :src="getCameraImageUrl(cameraNumber)">
</div> </div>
</template> </template>
<style scoped> <style scoped>
@ -40,10 +45,10 @@
} }
.video-section { .video-section {
width: 100%; /* Adjust according to your layout */ width: 100%;
height: 100%; /* Adjust according to your layout */ height: 100%;
box-sizing: border-box; box-sizing: border-box;
border: 2px solid #ccc; /* Adding a small border */ border: 2px solid #ccc;
} }
.video-section video { .video-section video {
@ -51,7 +56,7 @@
height: 100%; height: 100%;
} }
.box{ .box{
border: 2px solid #030303; /* Adding a small border */ border: 2px solid #030303;
} }
</style> </style>

12
src/views/Cam1Focus.vue Normal file
View File

@ -0,0 +1,12 @@
<script setup lang="ts">
import Camera from "../components/Camera.vue";
</script>
<template>
<div class="grid">
<div>
<Camera :cameraNumber="1"/>
</div>
</div>
</template>

View File

@ -6,16 +6,16 @@ import Camera from "../components/Camera.vue";
<template> <template>
<div class="grid"> <div class="grid">
<div> <div>
<Camera/> <Camera :cameraNumber="1"/>
</div> </div>
<div> <div>
<Camera/> <Camera :cameraNumber="2"/>
</div> </div>
<div> <div>
<Camera/> <Camera :cameraNumber="2"/>
</div> </div>
<div> <div>
<Camera/> <Camera :cameraNumber="1"/>
</div> </div>
</div> </div>
</template> </template>