鱼眼去锯齿

import math

WIDTH = 3000
HEIGHT = 3000

# 计算两点之间的距离
def distance(x1, y1, x2, y2):
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

# 找出圆内所有像素点
with open("output1.txt", "w") as f:
    for y in range(HEIGHT):
        for x in range(WIDTH):
            d = distance(x, y, 1500, 1500)
            if d <= 1440:
                f.write("({}, {})\n".format(x, y))
# 读取output.txt文件中的坐标点 x 和 y 的列表
with open("output.txt", "r") as f:
    points1 = [tuple(map(int, point.strip()[1:-1].split(','))) for point in f]

# 读取output1.txt文件中的坐标点 x 和 y 的列表
with open("output1.txt", "r") as f:
    points2 = [tuple(map(int, point.strip()[1:-1].split(','))) for point in f]

# 获取不同的坐标点
points_diff = list(set(points1).symmetric_difference(set(points2)))

# 保存不同的坐标点到output2.txt文件中
with open("output2.txt", "w") as f:
    for p in points_diff:
        f.write("({}, {})\n".format(p[0], p[1]))
import cv2

# Load fisheye image
img = cv2.imread('fisheye.jpg')

# 读取包含坐标点信息的文件
with open("output2.txt", "r") as f:
    # 将每行数据转化为元组类型,并将其转化为列表
    points = [tuple(map(int, point.strip()[1:-1].split(','))) for point in f]

# 遍历所有点并将其设置为黑色
for p in points:
    cv2.circle(img, p, 1, (0, 0, 0), -1)

# 保存修改后的图像
cv2.imwrite("output.jpg", img)

import numpy as np

# 定义图像分辨率
WIDTH = 3000
HEIGHT = 3000

# 加载 YUV 文件
with open("test.yuv", "rb") as f:
    # 读取所有像素数据,以及 U/V 分量数据
    y_data = np.fromfile(f, dtype=np.uint8, count=WIDTH*HEIGHT).reshape((HEIGHT, WIDTH))
    u_data = np.fromfile(f, dtype=np.uint8, count=WIDTH*HEIGHT//4).reshape((HEIGHT//2, WIDTH//2))
    v_data = np.fromfile(f, dtype=np.uint8, count=WIDTH*HEIGHT//4).reshape((HEIGHT//2, WIDTH//2))

# 读取包含坐标点信息的文件
with open("output2.txt", "r") as f:
    # 将每行数据转化为元组类型,并将其转化为列表
    points = [tuple(map(int, point.strip()[1:-1].split(','))) for point in f]

# 将指定像素点的 Y、U、V 值设置为指定值
for p in points:
    y, x = p
    if x < 0 or x >= WIDTH or y < 0 or y >= HEIGHT:
        continue  # 跳过越界点
    y_data[y, x] = 17
    u_data[y//2, x//2] = 128
    v_data[y//2, x//2] = 128

# 将修改后的像素数据写回到 YUV 文件中
with open("output.yuv", "wb") as f:
    y_data.tofile(f)
    u_data.tofile(f)
    v_data.tofile(f)

你可能感兴趣的:(机器视觉,linux)