问题记录
2026-04-03

emqx连接问题

Linux内核4.12以下的版本,默认会开启tcp_tw_recycle,系统会主动回收处于TIME_WAIT状态的连接,适用于高并发短连接场景。

tcp_tw_recycle的回收连接逻辑是根据:源IP+时间戳判断是否回收连接,当emqx部署在开启了tcp_tw_recycle的服务器上时,在同一局域网中,有多个mqtt客户端连接上emqx,会导致连接一直中断,并且会触发云服务商的连接保护,屏蔽ip地址。

centos7内核低于4.12,关闭方式:

echo 0 > /proc/sys/net/ipv4/tcp_tw_recycle

视觉识别中关于倾斜图片校正为水平矩形

def get_rotate_crop_image(img, points):
    # 计算裁剪区域的宽高
    img_crop_width = int(max(
        np.linalg.norm(points[0] - points[1]),
        np.linalg.norm(points[2] - points[3])))
    
    img_crop_height = int(max(
        np.linalg.norm(points[0] - points[3]),
        np.linalg.norm(points[1] - points[2])))
    
    # 标准目标坐标 (矩形)
    pts_std = np.float32([[0, 0], [img_crop_width, 0],
                          [img_crop_width, img_crop_height],
                          [0, img_crop_height]])
    
    points = points.astype(np.float32)
    
    # 透视变换核心
    M = cv2.getPerspectiveTransform(points, pts_std)  # 计算变换矩阵
    dst_img = cv2.warpPerspective(                   # 执行透视变换
        img, M, (img_crop_width, img_crop_height),
        borderMode=cv2.BORDER_REPLICATE,
        flags=cv2.INTER_CUBIC)
    
    # 如果高宽比 >= 1.5,旋转 90 度
    if dst_img_height * 1.0 / dst_img_width >= 1.5:
        dst_img = np.rot90(dst_img)
    
    return dst_img