CanvasRenderingContext2D not work´s in angular 15

I’m doing an exercise using Angular v-15; it involves capturing video frames from the webcam and rendering them using “getContext” and replicating them with “requestAnimationFrame”.

I have two HTML components; one is the webcam stream, and the other is the canvas that draws what it captures from the video.

The problem I have is that in the “card-header” class div nothing changes; Only the initial dark gray color is visible. It doesn’t even turn black as if it were transmitting something.

This is the HTML file:

<nav class="navbar navbar-dark bg-dark">
    <a class="navbar-brand" href="#">Login - FaceApi</a>
</nav>

<div class="container">
    <div class="row">

        <div class="col-4"></div>
        <div class="col-4" style="margin-top: 150px;">
            <div class="jumbotron" style="text-align: center; border: 1px solid rgb(0, 0, 0);">
                <h3> <i class="fas fa-video-camera"></i> Login - Face</h3>
                <hr>
                <button type="button" class="btn btn-outline-secondary" data-toggle="modal" data-target="#staticBackdrop">Login</button>
            </div>
        </div>
        <div class="col-4"></div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade mt-5" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="staticBackdropLabel">Identificación Facial</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
        <div class="modal-body">
            <div class="card text-white bg-dark mb-3">
                <div class="card-header bg-dark">Cámara de Identificación</div>
                  <video style="position: absolute; top:0; visibility: hidden; left:0; opacity: 0;" width="640" height="480" autoplay muted #videoContainer></video>
                  <canvas width="640" height="480" #myCanvas></canvas>
              </div>
          
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary" (click)="detectar()">Detectar rostro</button>
          <button type="button" class="btn btn-secondary" (click)="removerVideo()">Close</button>
        </div>
      </div>
    </div>
  </div>

and this is the TS file

import { HttpClient } from '@angular/common/http';
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { environment } from 'src/environments/environment';

const URL = environment.urlServer;

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {

  @ViewChild('videoContainer', {static:true}) videoContainer!:ElementRef;
  @ViewChild('myCanvas', {static:true}) myCanvas!:ElementRef;

  public context!:CanvasRenderingContext2D;

  constructor(private http:HttpClient){}

  ngOnInit(): void {
    
  }

  detectar(){
    this.main();
  }
  removerVideo(){
    location.reload();
  }
  main = async()=>{
    this.context = this.myCanvas.nativeElement.getContext('2d');
    var video = await navigator.mediaDevices.getUserMedia({ video:true});

    this.videoContainer.nativeElement.srcObjet = video;

    const reDraw = async()=>{
      this.context.drawImage(this.videoContainer.nativeElement, 0, 0, 640, 480);

      requestAnimationFrame(reDraw);
      
    }

    requestAnimationFrame(reDraw);

  }
  

}

It is supposed to use webcam streaming via “getUSerMedia”.
Capture the video context with “getContext”.
And “drawImage” should draw what it has captured from the video div and display it on request of a canvas.

The console doesn’t give me any errors.
The web browser asks me for permissions to use the camera and I accept them; The IR LED on the webcam turns on, a sign that it is capturing.
I have tried in several browsers but the result is always the same.

I’m using VS code and git to write and mount the servers.

–Angular CLI: 15.2.11
–Node v14.21.3
–npm v6.14.18
–VScode v1.90.1

New contributor

Alberto García is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật