日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人工智能 > pytorch >内容正文

pytorch

Opencv级联分类器实现人脸识别

發(fā)布時(shí)間:2024/7/19 pytorch 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Opencv级联分类器实现人脸识别 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在本章中,我們將學(xué)習(xí)如何使用OpenCV使用系統(tǒng)相機(jī)捕獲幀。org.opencv.videoio包的VideoCapture類包含使用相機(jī)捕獲視頻的類和方法。讓我們一步一步學(xué)習(xí)如何捕捉幀 -

第1步:加載OpenCV本機(jī)庫

在使用OpenCV庫編寫Java代碼時(shí),您需要做的第一步是使用loadLibrary()加載OpenCV的本機(jī)庫。加載OpenCV本機(jī)庫,如下所示。

// Loading the core library System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

第2步:實(shí)例化視頻捕獲類

使用前面本教程中提到的任何函數(shù)來實(shí)例化Mat類。

// Instantiating the VideoCapture class (camera:: 0) VideoCapture capture = new VideoCapture(0);

第3步:讀取幀

您可以使用VideoCapture類的read()方法從相機(jī)中讀取幀。此方法接受Mat類的對象來存儲讀取的幀。

// Reading the next video frame from the camera Mat matrix = new Mat(); capture.read(matrix);

代碼:

1 package com.gitee.dgw.Camera; 2 3 import javafx.application.Application; 4 import javafx.embed.swing.SwingFXUtils; 5 import javafx.scene.Group; 6 import javafx.scene.Scene; 7 import javafx.scene.image.ImageView; 8 import javafx.scene.image.WritableImage; 9 import javafx.stage.Stage; 10 import org.opencv.core.Mat; 11 import org.opencv.imgcodecs.Imgcodecs; 12 import org.opencv.videoio.VideoCapture; 13 14 import java.awt.image.BufferedImage; 15 import java.awt.image.DataBufferByte; 16 import java.awt.image.WritableRaster; 17 18 public class CameraSnapshotJavaFX extends Application { 19 20 static { 21 platformUtils.loadLibraries(); 22 } 23 Mat matrix = null; 24 25 @Override 26 public void start(Stage stage) { 27 // Capturing the snapshot from the camera 28 CameraSnapshotJavaFX obj = new CameraSnapshotJavaFX(); 29 WritableImage writableImage = obj.capureSnapShot(); 30 31 // Saving the image 32 obj.saveImage(); 33 34 // Setting the image view 35 ImageView imageView = new ImageView(writableImage); 36 37 // setting the fit height and width of the image view 38 imageView.setFitHeight(400); 39 imageView.setFitWidth(600); 40 41 // Setting the preserve ratio of the image view 42 imageView.setPreserveRatio(true); 43 44 // Creating a Group object 45 Group root = new Group(imageView); 46 47 // Creating a scene object 48 Scene scene = new Scene(root, 600, 400); 49 50 // Setting title to the Stage 51 stage.setTitle("Capturing an image"); 52 53 // Adding scene to the stage 54 stage.setScene(scene); 55 56 // Displaying the contents of the stage 57 stage.show(); 58 } 59 public WritableImage capureSnapShot() { 60 WritableImage WritableImage = null; 61 62 63 // Instantiating the VideoCapture class (camera:: 0) 64 VideoCapture capture = new VideoCapture(0); 65 66 // Reading the next video frame from the camera 67 Mat matrix = new Mat(); 68 capture.read(matrix); 69 70 // If camera is opened 71 if( capture.isOpened()) { 72 // If there is next video frame 73 if (capture.read(matrix)) { 74 // Creating BuffredImage from the matrix 75 BufferedImage image = new BufferedImage(matrix.width(), 76 matrix.height(), BufferedImage.TYPE_3BYTE_BGR); 77 78 WritableRaster raster = image.getRaster(); 79 DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer(); 80 byte[] data = dataBuffer.getData(); 81 matrix.get(0, 0, data); 82 this.matrix = matrix; 83 84 // Creating the Writable Image 85 WritableImage = SwingFXUtils.toFXImage(image, null); 86 } 87 } 88 return WritableImage; 89 } 90 public void saveImage() { 91 // Saving the Image 92 String file = "z://sanpshot.jpg"; 93 94 // Instantiating the imgcodecs class 95 Imgcodecs imageCodecs = new Imgcodecs(); 96 97 // Saving it again 98 imageCodecs.imwrite(file, matrix); 99 } 100 public static void main(String args[]) { 101 launch(args); 102 } 103 }

?






轉(zhuǎn)載于:https://www.cnblogs.com/dgwblog/p/9440160.html

總結(jié)

以上是生活随笔為你收集整理的Opencv级联分类器实现人脸识别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。