青岛 网站开发建设网站需要几个步骤
青岛 网站开发,建设网站需要几个步骤,做饰品网站,wordpress调用代码文章目录 前言一、试过的方法二、最终使用的方法1.先极坐标变换2.计算斜率 总结 前言 想了挺久#xff0c;一直没解决这个问题。后面勉强解决了。 一、试过的方法
1.想用圆度来解决#xff0c;后来发现圆度差值很小#xff0c;完整的圆圆度0.89#xff0c;然后有缺角的圆圆… 文章目录 前言一、试过的方法二、最终使用的方法1.先极坐标变换2.计算斜率 总结 前言 想了挺久一直没解决这个问题。后面勉强解决了。 一、试过的方法
1.想用圆度来解决后来发现圆度差值很小完整的圆圆度0.89然后有缺角的圆圆度0.88。 2.想用面积来解决但是图片中每个圆大小不是一致的是有一些差别的也没办法。 3.多边形拟合、凸包都不合适。 4.想使用角点的数量来确定发现也是不行。看下图
二、最终使用的方法
1.先极坐标变换
代码如下示例
import cv2
import os# 设置文件夹路径
folder_path rE:\VSCODE_PY\CAPCode\Posong\cap_2# 遍历文件夹中的图像文件
for file_name in os.listdir(folder_path):if file_name.endswith(.jpg):# 读取图像并转换为灰度图像image_path os.path.join(folder_path, file_name)image cv2.imread(image_path)gray cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 进行极坐标变换polar_image cv2.linearPolar(gray, (gray.shape[1]//2, gray.shape[0]//2), gray.shape[1]//210, cv2.WARP_FILL_OUTLIERS)# 进行边缘检测edges cv2.Canny(polar_image, 50, 150)# 保存处理后的图像output_path os.path.join(folder_path, polar_ file_name)cv2.imwrite(output_path, polar_image)极坐标的中心点可以根据实际情况设置一下。
2.计算斜率
代码如下示例
import os
import cv2
import numpy as np# 设置最小间距阈值
min_distance 10# 遍历cap_8文件夹内的所有图片
for filename in os.listdir(rE:\VSCODE_PY\CAPCode\Posong\cap_8):if filename.endswith(.jpg):# 读取图像并进行灰度化处理image cv2.imread(os.path.join(rE:\VSCODE_PY\CAPCode\Posong\cap_8, filename))gray cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 进行边缘检测edges cv2.Canny(gray, 50, 150)# 查找轮廓contours, _ cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# 创建一个空白图像用于绘制轮廓contour_image np.zeros_like(image)# 绘制轮廓cv2.drawContours(contour_image, contours, -1, (0, 255, 0), 2)# 查找角点corners cv2.cornerHarris(gray, 2, 3, 0.04)# 标记角点threshold 0.45 * corners.max() # 调整阈值corners cv2.dilate(corners, None)image[corners threshold] [0, 0, 255]# 计算任意两个角点之间的斜率corner_points np.argwhere(corners threshold)slopes []for i in range(len(corner_points)):for j in range(i1, len(corner_points)):x1, y1 corner_points[i]x2, y2 corner_points[j]distance np.sqrt((x2 - x1) ** 2 (y2 - y1) ** 2)if distance min_distance:if x2 - x1 0:slope float(inf)else:slope (y2 - y1) / (x2 - x1)slopes.append(slope)# 处理无穷大和无穷小的情况slopes [slope for slope in slopes if slope ! float(inf) and slope ! float(-inf)]slopes.sort()# 输出最大斜率和最小斜率的绝对值if len(slopes) 2:max_slope max(abs(slopes[-2]), abs(slopes[1]))min_slope min(abs(slopes[-2]), abs(slopes[1]))else:max_slope float(-inf)min_slope float(inf)print(图片{}的最大斜率的绝对值:.format(filename), max_slope)print(图片{}的最小斜率的绝对值:.format(filename), min_slope)# 显示结果cv2.imshow(Contours with Corners, image)cv2.waitKey(0)cv2.destroyAllWindows()
角点稍微多要先设置一下任意2个角点的斜率必须大于最小间距。 这样可以求出每一张图片的斜率绝对值最大和最小值即看下凸起部分是不是影响到了曲线的斜率。 总结
完成。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/89983.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!