opencv实现回形遍历像素算法
作者:ancy_i_cv 时间:2021-12-26 01:49:30
本文实例为大家分享了opencv实现回形遍历像素算法的具体代码,供大家参考,具体内容如下
代码实现
# -*- coding:utf-8 -*-
import cv2
import numpy as np
cv2.namedWindow('img', 0)
def traversePixelByCycloidLine(image):
"""
从一副灰度图像的中心开始向边缘按回形线的方式遍历所有像素,每个像素只能访问一次。
我目前实现了基本的算法, 但存在以下问题:
1) 只支持方阵, 且行列为奇数
2) 只实现, 代码没整理
"""
h, w = image.shape[:2]
assert h == w and h % 2 == 1, '只支持方阵, 且行列为奇数'
center_x, center_y = [w // 2, h // 2]
traverse_num = h * w
cycloid_num = 0
value = 1
while True:
for i in range(cycloid_num * 2 + 1):
if value >= traverse_num:
return image
center_x = center_x + 1
image[center_y, center_x] = 255
value += 1
cv2.imshow('img', image)
cv2.waitKey(33)
for i in range(cycloid_num * 2 + 1):
if value >= traverse_num:
return image
center_y = center_y + 1
image[center_y, center_x] = 255
value += 1
cv2.imshow('img', image)
cv2.waitKey(33)
for i in range(cycloid_num * 2 + 2):
if value >= traverse_num:
return image
center_x = center_x - 1
image[center_y, center_x] = 255
value += 1
cv2.imshow('img', image)
cv2.waitKey(33)
for i in range(cycloid_num * 2 + 2):
if value >= traverse_num:
return image
center_y = center_y - 1
image[center_y, center_x] = 255
value += 1
cv2.imshow('img', image)
cv2.waitKey(33)
cycloid_num += 1
image_wh = 11
while True:
image = np.zeros((image_wh, image_wh, 3), dtype=np.uint8)
traversePixelByCycloidLine(image)
效果展示
来源:https://blog.csdn.net/u014072827/article/details/114373552
标签:opencv,遍历,算法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python多路复用selector模块的基本使用
2021-12-17 08:43:25
避免Adodb.Stream输出UTF-8时自动写入的BOM(asp)
2011-08-24 20:32:56
Python下Fabric的简单部署方法
2023-11-08 07:17:11
mac 上配置Pycharm连接远程服务器并实现使用远程服务器Python解释器的方法
2021-10-19 18:40:40
![](https://img.aspxhome.com/file/2023/8/127318_0s.png)
基于python爬取链家二手房信息代码示例
2022-09-01 18:36:25
![](https://img.aspxhome.com/file/2023/5/105085_0s.jpg)
分享7个 Python 实战项目练习
2022-03-18 01:52:39
php网络安全中命令执行漏洞的产生及本质探究
2023-05-30 05:34:31
matlab中imadjust函数的作用及应用举例
2021-09-12 21:34:06
![](https://img.aspxhome.com/file/2023/6/82736_0s.jpg)
Python给定一个句子倒序输出单词以及字母的方法
2022-11-21 00:36:50
MYSQL数据库表设计与优化(一)
2010-10-25 19:50:00
python实现将视频按帧读取到自定义目录
2023-07-15 01:24:11
Python数字图像处理代数之加减乘运算
2023-03-20 07:51:26
![](https://img.aspxhome.com/file/2023/7/82667_0s.png)
Python数据分析基础之文件的读取
2022-10-16 21:25:21
解决Atom安装Hydrogen无法运行python3的问题
2021-07-19 22:16:01
![](https://img.aspxhome.com/file/2023/7/89437_0s.jpg)
python中subprocess实例用法及知识点详解
2022-12-03 00:27:39
python3学习笔记之多进程分布式小例子
2022-08-23 04:46:07
![](https://img.aspxhome.com/file/2023/0/103320_0s.png)
python获取图片颜色信息的方法
2023-11-10 16:40:41
在漏洞利用Python代码真的很爽
2023-11-24 15:57:29
python 利用panda 实现列联表(交叉表)
2022-02-21 02:24:32
![](https://img.aspxhome.com/file/2023/0/68990_0s.jpg)
Go语言学习之反射的用法详解
2023-06-16 06:40:40
![](https://img.aspxhome.com/file/2023/1/86281_0s.png)