当前位置: 首页 > news >正文

郑州网站建设开发wordpress新用户

郑州网站建设开发,wordpress新用户,58同城网站的建设目标是什么,官方网站建设推广文章目录 概要通用配置不考虑间隔代码实现考虑间隔代码实现小结 概要 概要#xff1a; 拼图效果是一种将图像切割为相邻正方形并重新排列的艺术效果。在生成拼图效果时#xff0c;可以考虑不同的模式#xff0c;包括是否考虑间隔和如何处理不能整除的部分。 不考虑间隔 拼图效果是一种将图像切割为相邻正方形并重新排列的艺术效果。在生成拼图效果时可以考虑不同的模式包括是否考虑间隔和如何处理不能整除的部分。 不考虑间隔忽略不能整除部分 相邻正方形之间没有间隔同时高度不能整除的部分直接被忽略。 示例图中展示了正方形紧密排列没有任何间隔不整除的部分被舍弃。 不考虑间隔对不能整除部分进行空白填充 相邻正方形之间没有间隔同时对高度不能整除的部分进行白色填充。 示例图中呈现了正方形之间无缝连接高度不能整除的部分填充为白色。 考虑间隔忽略不能整除部分 相邻正方形之间存在间隙间隔距离为3像素同时高度不能整除的部分直接被忽略。 示例图中显示了正方形之间的间隔不整除的部分被舍弃。 考虑间隔对不能整除部分进行空白填充 相邻正方形之间存在间隙间隔距离为3像素同时对高度不能整除的部分进行白色填充。 示例图中演示了正方形之间的间隔高度不能整除的部分填充为白色。 通用配置 为了统一上述代码,我们设置通用配置项如下: config {cell_num:7,whether_crop_image_height: True,whether_with_gap: True,gap_width:3 }上述配置中,各项含义如下: cell_num: 表示每行划分格子个数 whether_crop_image_height: 表示是否对高度不能整除部分进行空白填充 whether_with_gap: 表示相邻正方形之间是否存在间隔 gap_width: 表示相邻正方形间间隔的大小 不考虑间隔代码实现 1). 获取每行格子数目和输入图像信息 w_count config[cell_num] src_height img.shape[0] src_width img.shape[1]2).计算每个格子的长度以及结果图像的宽度 sub_length int(src_width / w_count) new_width sub_length * w_count3).根据是否需要对高度进行空白填充,计算结果图像的高度 if config[whether_crop_image_height]:h_count int(src_height / sub_length) else:h_count math.ceil(src_height / sub_length) new_height sub_length * h_count4).对结果图进行赋值 img_t np.zeros(shape(new_height,new_width,3),dtypenp.uint8) 255 if config[whether_crop_image_height]:img_t img[:new_height,:new_width,:] else:img_t[:src_height, :new_width, :] img[:src_height, :new_width, :]5).画格子 for x_i in range(1, w_count):cv2.line(img_t,(x_i*sub_length,0),(x_i*sub_length,new_height-1),color(205,205,74),thickness1) for y_i in range(1, h_count):cv2.line(img_t,(0,y_i*sub_length),(new_width-1,y_i*sub_length), color(205,205,74), thickness1)完整代码 import cv2 import numpy as np import math# 通用配置 config {cell_num: 7,whether_crop_image_height: True,whether_with_gap: False,gap_width: 0 }# 读取图像 img cv2.imread(img.png)# 获取每行格子数目和输入图像信息 w_count config[cell_num] src_height img.shape[0] src_width img.shape[1]# 计算每个格子的长度以及结果图像的宽度 sub_length int(src_width / w_count) new_width sub_length * w_count# 根据是否需要对高度进行空白填充计算结果图像的高度 if config[whether_crop_image_height]:h_count int(src_height / sub_length) else:h_count math.ceil(src_height / sub_length) new_height sub_length * h_count# 对结果图进行赋值 img_t np.zeros(shape(new_height, new_width, 3), dtypenp.uint8) 255 if config[whether_crop_image_height]:img_t img[:new_height, :new_width, :] else:img_t[:src_height, :new_width, :] img[:src_height, :new_width, :]# 画格子 for x_i in range(1, w_count):cv2.line(img_t, (x_i * sub_length, 0), (x_i * sub_length, new_height-1), color(205, 205, 74), thickness1) for y_i in range(1, h_count):cv2.line(img_t, (0, y_i * sub_length), (new_width-1, y_i * sub_length), color(205, 205, 74), thickness1)# 展示生成的拼图效果 cv2.imshow(Mosaic Effect, img_t) cv2.waitKey(0) cv2.destroyAllWindows() 带填充的结果 import cv2 import numpy as np import math# 通用配置 config {cell_num: 7,whether_crop_image_height: True,whether_with_gap: False,gap_width: 0 }# 读取图像 img cv2.imread(img.png)# 获取每行格子数目和输入图像信息 w_count config[cell_num] src_height img.shape[0] src_width img.shape[1]# 计算每个格子的长度、间隔长度以及结果图像的宽度 sub_length int(src_width / w_count) gap_length int(config[gap_width]) new_width sub_length * w_count gap_length * (w_count - 1)# 根据是否需要对高度进行空白填充计算结果图像的高度 if config[whether_crop_image_height]:h_count int((src_height gap_length) / (sub_length gap_length)) else:h_count math.ceil((src_height gap_length) / (sub_length gap_length)) new_height sub_length * h_count gap_length * (h_count - 1)# 对结果图进行赋值 img_t np.zeros(shape(new_height, new_width, 3), dtypenp.uint8) 255 if config[whether_crop_image_height]:for i in range(h_count):for j in range(w_count):begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yimg_t[src_y:src_y sub_length, src_x:src_x sub_length, :] img[begin_y:begin_y sub_length, begin_x:begin_x sub_length, :] else:for i in range(h_count):for j in range(w_count):begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yif i h_count - 1:img_t[src_y:src_y sub_length, src_x:src_x sub_length, :] img[begin_y:begin_y sub_length, begin_x:begin_x sub_length, :]else:diff_height src_height - sub_length * (h_count - 1)img_t[src_y:src_y diff_height, src_x:src_x sub_length, :] img[begin_y:begin_y diff_height, begin_x:begin_x sub_length, :]# 展示生成的拼图效果 cv2.imshow(Mosaic Effect with Fill, img_t) cv2.waitKey(0) cv2.destroyAllWindows() 不考虑间隔带填充的情况img_t np.zeros(shape(new_height, new_width, 3), dtypenp.uint8) 255 if config[whether_crop_image_height]:img_t img[:new_height, :new_width, :] else:img_t[:src_height, :new_width, :] img[:src_height, :new_width, :]考虑间隔带填充的情况img_t np.zeros(shape(new_height, new_width, 3), dtypenp.uint8) 255 if config[whether_crop_image_height]:for i in range(h_count):for j in range(w_count):begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yimg_t[src_y:src_y sub_length, src_x:src_x sub_length, :] img[begin_y:begin_y sub_length, begin_x:begin_x sub_length, :] else:for i in range(h_count):for j in range(w_count):begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yif i h_count - 1:img_t[src_y:src_y sub_length, src_x:src_x sub_length, :] img[begin_y:begin_y sub_length, begin_x:begin_x sub_length, :]else:diff_height src_height - sub_length * (h_count - 1)img_t[src_y:src_y diff_height, src_x:src_x sub_length, :] img[begin_y:begin_y diff_height, begin_x:begin_x sub_length, :]在带填充的情况下会对不能整除的高度部分进行空白填充。带填充的拼图效果会更整齐而不带填充的情况下可能会有一些截断。 考虑间隔代码实现 1). 获取每行格子数目和输入图像信息 w_count config[cell_num] src_height img.shape[0] src_width img.shape[1]2).计算每个格子的长度,间隔长度以及结果图像的宽度 sub_length int(src_width / w_count) gap_length int(config[gap_width]) new_width sub_length * w_count gap_length * (w_count -1)3).根据是否需要对高度进行空白填充,计算结果图像的高度 if config[whether_crop_image_height]:h_count int( (src_height gap_length) / (sub_lengthgap_length)) else:h_count math.ceil((src_height gap_length) / (sub_lengthgap_length)) new_height sub_length * h_count gap_length * (h_count-1)4).对结果图进行赋值 img_t np.zeros(shape(new_height,new_width,3),dtypenp.uint8) 255 if config[whether_crop_image_height]:for i in range(h_count): for j in range(w_count): begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yimg_t[src_y:src_ysub_length,src_x:src_x sub_length,:] img[begin_y:begin_y sub_length,begin_x:begin_x sub_length, :] else:for i in range(h_count): for j in range(w_count): begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yif ih_count-1:img_t[src_y:src_ysub_length,src_x:src_x sub_length,:] img[begin_y:begin_y sub_length,begin_x:begin_x sub_length, :]else:diff_height src_height - sub_length * (h_count-1)img_t[src_y:src_y diff_height, src_x:src_x sub_length, :] img[begin_y:begin_y diff_height,begin_x:begin_x sub_length, :]全部代码 import cv2 import numpy as np import math# 通用配置 config {cell_num: 7,whether_crop_image_height: True,whether_with_gap: True,gap_width: 3 }# 读取图像 img cv2.imread(img.png)# 获取每行格子数目和输入图像信息 w_count config[cell_num] src_height img.shape[0] src_width img.shape[1]# 计算每个格子的长度、间隔长度以及结果图像的宽度 sub_length int(src_width / w_count) gap_length int(config[gap_width]) new_width sub_length * w_count gap_length * (w_count - 1)# 根据是否需要对高度进行空白填充计算结果图像的高度 if config[whether_crop_image_height]:h_count int((src_height gap_length) / (sub_length gap_length)) else:h_count math.ceil((src_height gap_length) / (sub_length gap_length)) new_height sub_length * h_count gap_length * (h_count - 1)# 对结果图进行赋值 img_t np.zeros(shape(new_height, new_width, 3), dtypenp.uint8) 255 if config[whether_crop_image_height]:for i in range(h_count):for j in range(w_count):begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yimg_t[src_y:src_y sub_length, src_x:src_x sub_length, :] img[begin_y:begin_y sub_length, begin_x:begin_x sub_length, :] else:for i in range(h_count):for j in range(w_count):begin_x sub_length * jbegin_y sub_length * isrc_x gap_length * j begin_xsrc_y gap_length * i begin_yif i h_count - 1:img_t[src_y:src_y sub_length, src_x:src_x sub_length, :] img[begin_y:begin_y sub_length, begin_x:begin_x sub_length, :]else:diff_height src_height - sub_length * (h_count - 1)img_t[src_y:src_y diff_height, src_x:src_x sub_length, :] img[begin_y:begin_y diff_height, begin_x:begin_x sub_length, :]# 绘制间隔 if config[whether_with_gap]:for i in range(h_count):for j in range(w_count - 1):begin_x sub_length * (j 1) gap_length * jbegin_y sub_length * i gap_length * icv2.line(img_t, (begin_x, begin_y), (begin_x, begin_y sub_length), color(205, 205, 74), thickness1)# 展示生成的带填充和间隔的拼图效果 cv2.imshow(Mosaic Effect with Fill and Gap, img_t) cv2.waitKey(0) cv2.destroyAllWindows() 小结 通过使用OpenCV库和Python编程语言实现了图像拼图效果的生成。 拼图效果生成 根据用户的需求实现了两种不同的拼图效果生成方式。 一种是不考虑间隔可以选择是否对高度不能整除的部分进行空白填充另一种是考虑间隔可以选择相邻正方形之间是否存在间隔以及间隔的大小同样可以选择是否对高度不能整除的部分进行空白填充。 通用配置 引入了通用配置项用户可以通过修改配置来调整拼图的格子数、是否裁剪高度、是否考虑间隔以及间隔的宽度等参数。 代码优化 封装了一些功能函数使代码更加模块化和可读性更强。
http://www.pierceye.com/news/84854/

相关文章:

  • 运动服装商城网站建设内网网站建设方面政策
  • 汤唯梁朝伟做视频网站排名好的网站关键词优化企业
  • 邯郸做移动网站价格表网站建设安全问题
  • 建设工程方面的资料在哪个网站下载比较方便企业网站优化的弊端
  • visual c 网站开发触动网站建设
  • 顺的网站建设策划asp做网站优点
  • 营销型企业网站名词解释网页设计与网站建设程序作业
  • 网站维护计划网站开发后端框架
  • 怎么在门户网站上发布免费wordpress资源
  • 贵阳网站开发培训网站开发培训 价格
  • 广东上海专业网站建设公司哪家好做房产网站用什么软件
  • php做网站软件wordpress安装论坛
  • vs2008不能新建网站服务器上如何做网站
  • 教育培训门户网站模板下载设计网页公司哪里好
  • 网站建设 上海网修水县城乡建设局网站
  • 小程序怎么做网站大男人直播视频
  • asp网站数据库连接制作网页的工具主要有哪些
  • 佛山网站搭建烟台赶集网网站建设
  • 做个网站多少钱一年青岛网站建设哪家更好
  • 宽屏网站源码服务器搭建网站环境
  • 成都科技网站建设咨询电话自己做的电影网站犯法吗
  • 网站代码如何导入营销手段有哪些
  • 济宁网站建设(深圳软件开发有限公司有几家
  • 博客网站快速排名平躺设计家官网
  • 桐城市住房和城乡建设局网站甘肃省建设工程168网站
  • 陕西建设网综合服务中心网站个人域名备案需要哪些资料
  • 全国做网站公司前十名北京住房和城乡建设网站
  • 做外贸有哪些网站比较好wordpress调用id数据
  • 软件定制网站建设本地网站制作
  • 织梦网站如何做二级导航栏wordpress推广提成