【CanMV K230 AI视觉】人脸姿态(脸部朝向)

news2024/9/24 3:25:46

【CanMV K230 AI视觉】人脸姿态(脸部朝向)

    • 人脸姿态(脸部朝向)

(动态测试效果可以去下面网站自己看。)

B站视频链接:已做成合集
抖音链接:已做成合集


人脸姿态(脸部朝向)

人脸姿态是在检测到人脸后通过3D矩形框描绘出脸部朝向,支持单个和多个人脸。
在这里插入图片描述

'''
实验名称:人脸姿态(脸部朝向)
实验平台:01Studio CanMV K230
教程:wiki.01studio.cc
'''

from libs.PipeLine import PipeLine, ScopedTiming
from libs.AIBase import AIBase
from libs.AI2D import Ai2d
import os
import ujson
from media.media import *
from time import *
import nncase_runtime as nn
import ulab.numpy as np
import time
import image
import aidemo
import random
import gc
import sys

# 自定义人脸检测任务类
class FaceDetApp(AIBase):
    def __init__(self,kmodel_path,model_input_size,anchors,confidence_threshold=0.25,nms_threshold=0.3,rgb888p_size=[1280,720],display_size=[1920,1080],debug_mode=0):
        super().__init__(kmodel_path,model_input_size,rgb888p_size,debug_mode)
        # kmodel路径
        self.kmodel_path=kmodel_path
        # 检测模型输入分辨率
        self.model_input_size=model_input_size
        # 置信度阈值
        self.confidence_threshold=confidence_threshold
        # nms阈值
        self.nms_threshold=nms_threshold
        self.anchors=anchors
        # sensor给到AI的图像分辨率,宽16字节对齐
        self.rgb888p_size=[ALIGN_UP(rgb888p_size[0],16),rgb888p_size[1]]
        # 视频输出VO分辨率,宽16字节对齐
        self.display_size=[ALIGN_UP(display_size[0],16),display_size[1]]
        # debug模式
        self.debug_mode=debug_mode
        # 实例化Ai2d,用于实现模型预处理
        self.ai2d=Ai2d(debug_mode)
        # 设置Ai2d的输入输出格式和类型
        self.ai2d.set_ai2d_dtype(nn.ai2d_format.NCHW_FMT,nn.ai2d_format.NCHW_FMT,np.uint8, np.uint8)

    # 配置预处理操作,这里使用了pad和resize,Ai2d支持crop/shift/pad/resize/affine,具体代码请打开/sdcard/app/libs/AI2D.py查看
    def config_preprocess(self,input_image_size=None):
        with ScopedTiming("set preprocess config",self.debug_mode > 0):
            # 初始化ai2d预处理配置,默认为sensor给到AI的尺寸,可以通过设置input_image_size自行修改输入尺寸
            ai2d_input_size=input_image_size if input_image_size else self.rgb888p_size
            # 计算padding参数,并设置padding预处理
            self.ai2d.pad(self.get_pad_param(), 0, [104,117,123])
            # 设置resize预处理
            self.ai2d.resize(nn.interp_method.tf_bilinear, nn.interp_mode.half_pixel)
            # 构建预处理流程,参数为预处理输入tensor的shape和预处理输出的tensor的shape
            self.ai2d.build([1,3,ai2d_input_size[1],ai2d_input_size[0]],[1,3,self.model_input_size[1],self.model_input_size[0]])

    # 自定义后处理,results是模型输出的array列表,这里使用了aidemo库的face_det_post_process接口
    def postprocess(self,results):
        with ScopedTiming("postprocess",self.debug_mode > 0):
            res = aidemo.face_det_post_process(self.confidence_threshold,self.nms_threshold,self.model_input_size[0],self.anchors,self.rgb888p_size,results)
            if len(res)==0:
                return res
            else:
                return res[0]

    # 计算padding参数
    def get_pad_param(self):
        dst_w = self.model_input_size[0]
        dst_h = self.model_input_size[1]
        # 计算最小的缩放比例,等比例缩放
        ratio_w = dst_w / self.rgb888p_size[0]
        ratio_h = dst_h / self.rgb888p_size[1]
        if ratio_w < ratio_h:
            ratio = ratio_w
        else:
            ratio = ratio_h
        new_w = (int)(ratio * self.rgb888p_size[0])
        new_h = (int)(ratio * self.rgb888p_size[1])
        dw = (dst_w - new_w) / 2
        dh = (dst_h - new_h) / 2
        top = (int)(round(0))
        bottom = (int)(round(dh * 2 + 0.1))
        left = (int)(round(0))
        right = (int)(round(dw * 2 - 0.1))
        return [0,0,0,0,top, bottom, left, right]

# 自定义人脸姿态任务类
class FacePoseApp(AIBase):
    def __init__(self,kmodel_path,model_input_size,rgb888p_size=[1920,1080],display_size=[1920,1080],debug_mode=0):
        super().__init__(kmodel_path,model_input_size,rgb888p_size,debug_mode)
        # kmodel路径
        self.kmodel_path=kmodel_path
        # 人脸姿态模型输入分辨率
        self.model_input_size=model_input_size
        # sensor给到AI的图像分辨率,宽16字节对齐
        self.rgb888p_size=[ALIGN_UP(rgb888p_size[0],16),rgb888p_size[1]]
        # 视频输出VO分辨率,宽16字节对齐
        self.display_size=[ALIGN_UP(display_size[0],16),display_size[1]]
        # debug模式
        self.debug_mode=debug_mode
        # 实例化Ai2d,用于实现模型预处理
        self.ai2d=Ai2d(debug_mode)
        # 设置Ai2d的输入输出格式和类型
        self.ai2d.set_ai2d_dtype(nn.ai2d_format.NCHW_FMT,nn.ai2d_format.NCHW_FMT,np.uint8, np.uint8)

    # 配置预处理操作,这里使用了affine,Ai2d支持crop/shift/pad/resize/affine,具体代码请打开/sdcard/app/libs/AI2D.py查看
    def config_preprocess(self,det,input_image_size=None):
        with ScopedTiming("set preprocess config",self.debug_mode > 0):
            # 初始化ai2d预处理配置,默认为sensor给到AI的尺寸,可以通过设置input_image_size自行修改输入尺寸
            ai2d_input_size=input_image_size if input_image_size else self.rgb888p_size
            # 计算affine矩阵并设置affine预处理
            matrix_dst = self.get_affine_matrix(det)
            self.ai2d.affine(nn.interp_method.cv2_bilinear,0, 0, 127, 1,matrix_dst)
            # 构建预处理流程,参数为预处理输入tensor的shape和预处理输出的tensor的shape
            self.ai2d.build([1,3,ai2d_input_size[1],ai2d_input_size[0]],[1,3,self.model_input_size[1],self.model_input_size[0]])

    # 自定义后处理,results是模型输出的array列表,计算欧拉角
    def postprocess(self,results):
        with ScopedTiming("postprocess",self.debug_mode > 0):
            R,eular = self.get_euler(results[0][0])
            return R,eular

    def get_affine_matrix(self,bbox):
        # 获取仿射矩阵,用于将边界框映射到模型输入空间
        with ScopedTiming("get_affine_matrix", self.debug_mode > 1):
            # 设置缩放因子
            factor = 2.7
            # 从边界框提取坐标和尺寸
            x1, y1, w, h = map(lambda x: int(round(x, 0)), bbox[:4])
            # 模型输入大小
            edge_size = self.model_input_size[1]
            # 平移距离,使得模型输入空间的中心对准原点
            trans_distance = edge_size / 2.0
            # 计算边界框中心点的坐标
            center_x = x1 + w / 2.0
            center_y = y1 + h / 2.0
            # 计算最大边长
            maximum_edge = factor * (h if h > w else w)
            # 计算缩放比例
            scale = edge_size * 2.0 / maximum_edge
            # 计算平移参数
            cx = trans_distance - scale * center_x
            cy = trans_distance - scale * center_y
            # 创建仿射矩阵
            affine_matrix = [scale, 0, cx, 0, scale, cy]
            return affine_matrix

    def rotation_matrix_to_euler_angles(self,R):
        # 将旋转矩阵(3x3 矩阵)转换为欧拉角(pitch、yaw、roll)
        # 计算 sin(yaw)
        sy = np.sqrt(R[0, 0] ** 2 + R[1, 0] ** 2)
        if sy < 1e-6:
            # 若 sin(yaw) 过小,说明 pitch 接近 ±90 度
            pitch = np.arctan2(-R[1, 2], R[1, 1]) * 180 / np.pi
            yaw = np.arctan2(-R[2, 0], sy) * 180 / np.pi
            roll = 0
        else:
            # 计算 pitch、yaw、roll 的角度
            pitch = np.arctan2(R[2, 1], R[2, 2]) * 180 / np.pi
            yaw = np.arctan2(-R[2, 0], sy) * 180 / np.pi
            roll = np.arctan2(R[1, 0], R[0, 0]) * 180 / np.pi
        return [pitch,yaw,roll]

    def get_euler(self,data):
        # 获取旋转矩阵和欧拉角
        R = data[:3, :3].copy()
        eular = self.rotation_matrix_to_euler_angles(R)
        return R,eular

# 人脸姿态任务类
class FacePose:
    def __init__(self,face_det_kmodel,face_pose_kmodel,det_input_size,pose_input_size,anchors,confidence_threshold=0.25,nms_threshold=0.3,rgb888p_size=[1280,720],display_size=[1920,1080],debug_mode=0):
        # 人脸检测模型路径
        self.face_det_kmodel=face_det_kmodel
        # 人脸姿态模型路径
        self.face_pose_kmodel=face_pose_kmodel
        # 人脸检测模型输入分辨率
        self.det_input_size=det_input_size
        # 人脸姿态模型输入分辨率
        self.pose_input_size=pose_input_size
        # anchors
        self.anchors=anchors
        # 置信度阈值
        self.confidence_threshold=confidence_threshold
        # nms阈值
        self.nms_threshold=nms_threshold
        # sensor给到AI的图像分辨率,宽16字节对齐
        self.rgb888p_size=[ALIGN_UP(rgb888p_size[0],16),rgb888p_size[1]]
        # 视频输出VO分辨率,宽16字节对齐
        self.display_size=[ALIGN_UP(display_size[0],16),display_size[1]]
        # debug_mode模式
        self.debug_mode=debug_mode
        self.face_det=FaceDetApp(self.face_det_kmodel,model_input_size=self.det_input_size,anchors=self.anchors,confidence_threshold=self.confidence_threshold,nms_threshold=self.nms_threshold,rgb888p_size=self.rgb888p_size,display_size=self.display_size,debug_mode=0)
        self.face_pose=FacePoseApp(self.face_pose_kmodel,model_input_size=self.pose_input_size,rgb888p_size=self.rgb888p_size,display_size=self.display_size)
        self.face_det.config_preprocess()

    # run函数
    def run(self,input_np):
        # 人脸检测
        det_boxes=self.face_det.run(input_np)
        pose_res=[]
        for det_box in det_boxes:
            # 对检测到的每一个人脸做人脸姿态估计
            self.face_pose.config_preprocess(det_box)
            R,eular=self.face_pose.run(input_np)
            pose_res.append((R,eular))
        return det_boxes,pose_res


    # 绘制人脸姿态角效果
    def draw_result(self,pl,dets,pose_res):
        pl.osd_img.clear()
        if dets:
            draw_img_np = np.zeros((self.display_size[1],self.display_size[0],4),dtype=np.uint8)
            draw_img=image.Image(self.display_size[0], self.display_size[1], image.ARGB8888,alloc=image.ALLOC_REF,data=draw_img_np)
            line_color = np.array([255, 0, 0 ,255],dtype=np.uint8)    #bgra
            for i,det in enumerate(dets):
                # (1)获取人脸姿态矩阵和欧拉角
                projections,center_point = self.build_projection_matrix(det)
                R,euler = pose_res[i]
                # (2)遍历人脸投影矩阵的关键点,进行投影,并将结果画在图像上
                first_points = []
                second_points = []
                for pp in range(8):
                    sum_x, sum_y = 0.0, 0.0
                    for cc in range(3):
                        sum_x += projections[pp][cc] * R[cc][0]
                        sum_y += projections[pp][cc] * (-R[cc][1])
                    center_x,center_y = center_point[0],center_point[1]
                    x = (sum_x + center_x) / self.rgb888p_size[0] * self.display_size[0]
                    y = (sum_y + center_y) / self.rgb888p_size[1] * self.display_size[1]
                    x = max(0, min(x, self.display_size[0]))
                    y = max(0, min(y, self.display_size[1]))
                    if pp < 4:
                        first_points.append((x, y))
                    else:
                        second_points.append((x, y))
                first_points = np.array(first_points,dtype=np.float)
                aidemo.polylines(draw_img_np,first_points,True,line_color,2,8,0)
                second_points = np.array(second_points,dtype=np.float)
                aidemo.polylines(draw_img_np,second_points,True,line_color,2,8,0)
                for ll in range(4):
                    x0, y0 = int(first_points[ll][0]),int(first_points[ll][1])
                    x1, y1 = int(second_points[ll][0]),int(second_points[ll][1])
                    draw_img.draw_line(x0, y0, x1, y1, color = (255, 0, 0 ,255), thickness = 2)
            pl.osd_img.copy_from(draw_img)

    def build_projection_matrix(self,det):
        x1, y1, w, h = map(lambda x: int(round(x, 0)), det[:4])
        # 计算边界框中心坐标
        center_x = x1 + w / 2.0
        center_y = y1 + h / 2.0
        # 定义后部(rear)和前部(front)的尺寸和深度
        rear_width = 0.5 * w
        rear_height = 0.5 * h
        rear_depth = 0
        factor = np.sqrt(2.0)
        front_width = factor * rear_width
        front_height = factor * rear_height
        front_depth = factor * rear_width  # 使用宽度来计算深度,也可以使用高度,取决于需求
        # 定义立方体的顶点坐标
        temp = [
            [-rear_width, -rear_height, rear_depth],
            [-rear_width, rear_height, rear_depth],
            [rear_width, rear_height, rear_depth],
            [rear_width, -rear_height, rear_depth],
            [-front_width, -front_height, front_depth],
            [-front_width, front_height, front_depth],
            [front_width, front_height, front_depth],
            [front_width, -front_height, front_depth]
        ]
        projections = np.array(temp)
        # 返回投影矩阵和中心坐标
        return projections, (center_x, center_y)


if __name__=="__main__":
    # 显示模式,默认"hdmi",可以选择"hdmi"和"lcd"
    display_mode="lcd"
    if display_mode=="hdmi":
        display_size=[1920,1080]
    else:
        display_size=[800,480]
    # 人脸检测模型路径
    face_det_kmodel_path="/sdcard/app/tests/kmodel/face_detection_320.kmodel"
    # 人脸姿态模型路径
    face_pose_kmodel_path="/sdcard/app/tests/kmodel/face_pose.kmodel"
    # 其它参数
    anchors_path="/sdcard/app/tests/utils/prior_data_320.bin"
    rgb888p_size=[1920,1080]
    face_det_input_size=[320,320]
    face_pose_input_size=[120,120]
    confidence_threshold=0.5
    nms_threshold=0.2
    anchor_len=4200
    det_dim=4
    anchors = np.fromfile(anchors_path, dtype=np.float)
    anchors = anchors.reshape((anchor_len,det_dim))

    # 初始化PipeLine,只关注传给AI的图像分辨率,显示的分辨率
    pl=PipeLine(rgb888p_size=rgb888p_size,display_size=display_size,display_mode=display_mode)
    pl.create()
    fp=FacePose(face_det_kmodel_path,face_pose_kmodel_path,det_input_size=face_det_input_size,pose_input_size=face_pose_input_size,anchors=anchors,confidence_threshold=confidence_threshold,nms_threshold=nms_threshold,rgb888p_size=rgb888p_size,display_size=display_size)

    clock = time.clock()

    try:
        while True:
            os.exitpoint()

            clock.tick()

            img=pl.get_frame()                      # 获取当前帧
            det_boxes,pose_res=fp.run(img)          # 推理当前帧
            print(det_boxes,pose_res)               # 打印结果
            fp.draw_result(pl,det_boxes,pose_res)   # 绘制推理效果
            pl.show_image()                         # 展示推理效果
            gc.collect()

            print(clock.fps()) #打印帧率

    except Exception as e:
        sys.print_exception(e)
    finally:
        fp.face_det.deinit()
        fp.face_pose.deinit()
        pl.destroy()
主代码变量说明
det_boxes人脸检测结果
pose_res姿态3D矩形

在这里插入图片描述

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2126664.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于yolov8的工程车辆挖掘机叉车卡车检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的工程车辆&#xff08;如挖掘机、叉车、卡车&#xff09;检测系统是一种利用先进深度学习技术的智能监控系统。该系统集成了YOLOv8算法&#xff0c;该算法以其高效的检测速度和准确的识别能力著称&#xff0c;特别适用于实时视频分析场景。 该系统通…

C2 Magic 附工具下载,供学习使用

最近&#xff0c;我们进行了一次安全演练&#xff0c;想要模拟一些复杂的攻击场景并测试我们的防御能力。这时&#xff0c;我想到了一款开源工具&#xff0c;它在处理抗沙箱后门启动和隐蔽ShellCode调用方面表现得非常出色。这款工具的设计理念是为了帮助安全团队更好地应对高级…

使用QT界面运行roslaunch,roslaunch,roscore等

QT通过界面运行rosrun,roslaunch,roscore等 QT 运行roslaunch加入ui界面修改cmakelist运行 使用qt界面运行rosrun&#xff0c;roscore,roslaunch等方法一方法二方法三 QT 运行roslaunch 首先需要使用QT安装好ROS插件&#xff0c;并且配置好环境&#xff0c;这个在之前的文章已…

nvm ls-remote: N/A

背景&#xff1a; 项目因为node版本问题运行失败&#xff0c;在彻底删除node后再重新安装 问题描述&#xff1a; 原因分析&#xff1a; 可能是因为终端不能获取镜像包 解决办法&#xff1a; 【方法一】 输入&#xff1a; step1. export NVM_NODEJS_ORG_MIRRORIndex of …

数据处理与统计分析篇-day01-Linux基础与环境搭建

day01-Linux基础 计算机简介 概述 电子计算机, 电脑, PC, Computer, 就是由 软件 硬件组成的 电子设备. 组成 计算机硬件 CPU(运算器, 控制器) 存储器(内存, 外存) 输入设备 输出设备 计算机软件 系统软件: 充当 用户 和 计算机硬件之间的 桥梁的. PC端: windows, Linu…

Elasticsearch 使用误区之五——单次请求获取大量数据

在使用 Elasticsearch 进行数据查询时&#xff0c;很多开发者、读者会遇到这样的问题&#xff1a;一次性检索大量数据&#xff0c;导致查询速度缓慢、网络延迟增加&#xff0c;甚至影响系统的整体性能。 单次获取过多数据不仅增加了网络传输的负担&#xff0c;还会使查询过程复…

Vue 中的 Web Workers:提升性能与流畅度

大家可能都听到过 Web Workers&#xff0c;那究竟如何使用呢&#xff1f;可以往下了解一下。 1. 什么是 Web Workers&#xff1f; Web Workers 是现代浏览器提供的一种机制&#xff0c;允许我们在主线程之外运行 JavaScript 脚本&#xff0c;避免阻塞 UI 渲染和用户交互操作。…

verilog vscode 与AI 插件

Verilog 轻量化开发环境 背景 笔者常用的开发环境 VIAVDO, 体积巨大&#xff0c;自带编辑器除了linting 能用&#xff0c;编辑器几乎不能用&#xff0c;仿真界面很友好&#xff0c;但是速度比较慢。Sublime Text, 非常好用的编辑器&#xff0c;各种插件使用verilog 非常方便…

深入理解Java虚拟机:Jvm总结-Java内存区域与内存溢出异常

第二章 Java内存区域与内存溢出异常 2.1 意义 对于C、C程序开发来说&#xff0c;程序员需要维护每一个对象从开始到终结。Java的虚拟自动内存管理机制&#xff0c;让java程序员不需要手写delete或者free代码&#xff0c;不容易出现内存泄漏和内存溢出问题&#xff0c;但是如果…

CSGHub携手Nvidia NIM、阿里计算巢打造企业级私有化部署解决方案

强强联合 人工智能与大数据的迅速发展&#xff0c;大模型的推理应用和资产管理已成为企业数字化转型的重要组成部分&#xff0c;企业正寻求高效、安全的AI模型部署解决方案。为应对日益增长的计算需求和复杂的数据管理挑战&#xff0c;CSGHub、Nvidia和阿里云计算巢强强联手&a…

Frozen CLIP: A Strong Backbone for Weakly Supervised Semantic Segmentation

摘要 弱监督语义分割在图像级标签方面取得了巨大的成就。最近的几种方法使用CLIP模型生成伪标签来训练单个分割模型&#xff0c;而没有尝试将CLIP模型作为主干&#xff0c;直接分割具有图像级标签的对象。在本文中&#xff0c;我们提出了 WeCLIP&#xff0c;一个基于 CLIP 的单…

【笔记】自动驾驶预测与决策规划_Part1_自动驾驶决策规划简介

自动驾驶决策规划简介 0、前言1、自动驾驶概述1.1 预测&#xff08;Prediction&#xff09;1.2 决策&#xff08;Decision Making&#xff09;1.3 规划&#xff08;Planning&#xff09; 2、自动驾驶历史和背景3、自动驾驶级别和分类4、预测决策规划的重要性4.1 预测的重要性4.…

环境搭建---部署rabbitmq集群

rabbitmq下载&#xff1a;https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.34/rabbitmq-server-generic-unix-3.8.34.tar.xz erlang下载&#xff1a;https://github.com/erlang/otp/releases/download/OTP-24.3.4.1/otp_src_24.3.4.1.tar.gz 配置主机名 …

MySQL原理之UUID主键分析,插入或更新语法分析

文章目录 1 MySQL不能用UUID做主键1.1 前言1.2 mysql和程序实例1.2.1 准备工作1.2.2 开始测试1.2.3 程序写入结果1.2.4 效率测试结果 1.3 使用uuid和自增id的索引结构对比1.3.1 自增id1.3.2 uuid 1.4 自增id缺点1.5 雪花算法 2 插入或更新2.1 on duplicate key2.1.1 定义2.1.2 …

git版本问题Your branch is behind ‘origin/dev‘by 2 commits,

git版本问题 一个不小心点击了版本的修改&#xff0c;于是就进入了翻滚中&#xff0c;回不来了 遇事还是不要慌&#xff0c;出现这个问题&#xff0c;如果那些你不需要&#xff0c;只是需要回到某一个版本&#xff0c;那么就是需要 git reset --hard origin/master 上面这就…

Vue3入门 - 登录功能开发(Vue3+ts+Pinia+Element Plus)

Vue3中实现登录功能&#xff0c;通常涉及到创建一个表单&#xff0c;用户输入用户名和密码&#xff0c;然后将信息发送到后端进行验证&#xff0c;得到响应结果后作出相应操作。 一、创建项目 这里他用pnpm进行项目的创建的&#xff0c;所以需要事先全局安装pnpm&#xff08;在…

神经网络的非线性激活

文章目录 一、神经网络的非线性激活是什么二、非线性激活常用函数三、非线性激活的实际演示 一、神经网络的非线性激活是什么 神经网络的非线性激活函数的主要作用是引入非线性变换&#xff0c;从而使网络能够学习和逼近复杂的函数关系。在神经网络中&#xff0c;线性变换&…

[产品管理-4]:NPDP新产品开发 - 2 - 战略 - 制定企业经营战略目标的结构化方法与工具

目录 一、SWOT分析工具 1、SWOT分析工具概述 2、SWOT分析与企业战略目标制定的关系 3、SWOT分析在企业战略目标制定中的应用实例 4、SWOT分析的改进与应用建议 二、P E S T L E 分 析&#xff1a;外部环境分析 2.1 概述 1. 政治因素&#xff08;Political&#xff09; …

COCOS:(飞机大战08)子弹和飞机添加碰撞器和刚体

做两个物体的碰撞有2种方式&#xff1a;碰撞检测和触发检测 这里子弹不能和飞机使用碰撞检测&#xff0c;因为会影响到敌机的运动&#xff0c;所有选择使用触发检测 从预制体Prefabs文件中&#xff0c;将子弹Bullet1和Bullet2拖到Canvas下 选中子弹&#xff0c;添加组件&#…

多线程:java中的实现

实现1&#xff1a; 通过java.util.concurrent.atomic中的原子性数据实现 static class Counter {// 通过加锁实现同步public static int count 0;public static final Object obj new Object(); // 通过原子性的整型来实现同步public static AtomicInteger c…