这是我的水下工作的开端 大二的夏天

我的挚友引导我接触了水下机器人

这是被更新后的第一代机器人

first rob

这台水下机器人是由郑嘉熙独立设计预组装,也是我第一次接触水下机器人的时候

这是最新一代由我组装的!

frame

下面是机器人简要的图像处理代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    # -*- coding: utf-8 -*-
    # 载入所需库
    import cv2
    import numpy as np
    import os
    import time
 
 
    def yolo_detect(pathIn='',
                    pathOut=None,
                    label_path='./cfg/coco.names',
                    config_path='./cfg/yolov3.cfg',
                    weights_path='./cfg/yolov3.weights',
                    confidence_thre=0.5,
                    nms_thre=0.3,
                    jpg_quality=80):
        '''
    pathIn:原始图片的路径
    pathOut:结果图片的路径
    label_path:类别标签文件的路径
    config_path:模型配置文件的路径
    weights_path:模型权重文件的路径
    confidence_thre:0-1,置信度(概率/打分)阈值,即保留概率大于这个值的边界框,默认为0.5
    nms_thre:非极大值抑制的阈值,默认为0.3
    jpg_quality:设定输出图片的质量,范围为0到100,默认为80,越大质量越好
    '''
 
    # 加载类别标签文件
    LABELS = open(label_path).read().strip().split("\n")
    nclass = len(LABELS)
 
    # 为每个类别的边界框随机匹配相应颜色
    np.random.seed(42)
    COLORS = np.random.randint(0, 255, size=(nclass, 3), dtype='uint8')
 
    # 载入图片并获取其维度
    base_path = os.path.basename(pathIn)
    img = cv2.imread(pathIn)
    (H, W) = img.shape[:2]
 
    # 加载模型配置和权重文件
    print('从硬盘加载YOLO......')
    net = cv2.dnn.readNetFromDarknet(config_path, weights_path)
 
    # 获取YOLO输出层的名字
    ln = net.getLayerNames()
    ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()]
 
    # 将图片构建成一个blob设置图片尺寸然后执行一次
    # YOLO前馈网络计算最终获取边界框和相应概率
    blob = cv2.dnn.blobFromImage(img, 1 / 255.0, (416, 416), swapRB=True, crop=False)
    net.setInput(blob)
    start = time.time()
    layerOutputs = net.forward(ln)
    end = time.time()
 
    # 显示预测所花费时间
    print('YOLO模型花费 {:.2f} 秒来预测一张图片'.format(end - start))
 
    # 初始化边界框置信度概率以及类别
    boxes = []
    confidences = []
    classIDs = []
 
    # 迭代每个输出层总共三个
    for output in layerOutputs:
        # 迭代每个检测
        for detection in output:
            # 提取类别ID和置信度
            scores = detection[5:]
            classID = np.argmax(scores)
            confidence = scores[classID]
 
            # 只保留置信度大于某值的边界框
            if confidence > confidence_thre:
                # 将边界框的坐标还原至与原图片相匹配记住YOLO返回的是
                # 边界框的中心坐标以及边界框的宽度和高度
                box = detection[0:4] * np.array([W, H, W, H])
                (centerX, centerY, width, height) = box.astype("int")
 
                # 计算边界框的左上角位置
                x = int(centerX - (width / 2))
                y = int(centerY - (height / 2))
 
                # 更新边界框置信度概率以及类别
                boxes.append([x, y, int(width), int(height)])
                confidences.append(float(confidence))
                classIDs.append(classID)
 
    # 使用非极大值抑制方法抑制弱重叠边界框
    idxs = cv2.dnn.NMSBoxes(boxes, confidences, confidence_thre, nms_thre)
 
    # 确保至少一个边界框
    if len(idxs) > 0:
        # 迭代每个边界框
        for i in idxs.flatten():
            # 提取边界框的坐标
            (x, y) = (boxes[i][0], boxes[i][1])
            (w, h) = (boxes[i][2], boxes[i][3])
 
            # 绘制边界框以及在左上角添加类别标签和置信度
            color = [int(c) for c in COLORS[classIDs[i]]]
            cv2.rectangle(img, (x, y), (x + w, y + h), color, 2)
            text = '{}: {:.3f}'.format(LABELS[classIDs[i]], confidences[i])
            (text_w, text_h), baseline = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 2)
            cv2.rectangle(img, (x, y - text_h - baseline), (x + text_w, y), color, -1)
            cv2.putText(img, text, (x, y - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 2)
 
    # 输出结果图片
    if pathOut is None:
        cv2.imwrite('with_box_' + base_path, img, [int(cv2.IMWRITE_JPEG_QUALITY), jpg_quality])
    else:
        cv2.imwrite(pathOut, img, [int(cv2.IMWRITE_JPEG_QUALITY), jpg_quality])
 
pathIn = '../image/yolo_test1.jpg'
pathOut = '../out/yolo_test1.jpg'
yolo_detect(pathIn,pathOut

报错盒子

这是报错的显示

Notification

Note: This is a notification box.

Warning

Warning: This is a warning box.

Error

Error: This is an error box.

最后就是我的工作照了

pull

throw

nice

answer 制作张拉结构 tensegrity