特别感谢:本文是我在博主元气少女缘结神的博客经纬度映射法校正鱼眼图像 程序的学习笔记,主要是通过python实现。
1.python程序
# -*- coding: utf-8 -*-
from __future__ import division
import cv2
import numpy as np
import math
# 读取鱼眼图片
img = cv2.imread("./TestImages/3.jpg")
# 设置灰度阈值
T = 40
# 转换为灰度图片
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 提取原图大小
rows, cols = img.shape[:2]
print(rows, cols)
# 从上向下扫描
for i in range(0, rows, 1):
for j in range(0, cols, 1):
if img_gray[i, j] >= T:
if img_gray[i + 1, j] >= T:
top = i
break
else:
continue
break
print('top =', top)
# 从下向上扫描
for i in range(rows - 1, -1, -1):
for j in range(0, cols, 1):
if img_gray[i, j] >= T:
if img_gray[i - 1, j] >= T:
bottom = i