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))
with open("output.txt", "r") as f:
points1 = [tuple(map(int, point.strip()[1:-1].split(','))) for point in f]
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)))
with open("output2.txt", "w") as f:
for p in points_diff:
f.write("({}, {})\n".format(p[0], p[1]))
import cv2
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
with open("test.yuv", "rb") as f:
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]
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
with open("output.yuv", "wb") as f:
y_data.tofile(f)
u_data.tofile(f)
v_data.tofile(f)