roi扩展0.2倍 python代码:

           x1, y1, x2, y2, track_id = valueif y2 - y1 < 35 or x2 - x1 < 35:continueif save_img:tmp = (datetime.datetime.now()).strftime("%S_%f")img_path=f"{dir_path}{track_id}_{tmp}.jpg"width_crop = x2-x1height_crop = y2-y1x1_new = int( max(0, x1 - width_crop * 0.1))y1_new =int( max(0, y1 - height_crop * 0.1))x2_new=int(min(image.shape[1],x2 + width_crop * 0.1))y2_new=int(min(image.shape[1],y2 + height_crop * 0.1))crop_img=image[y1_new:y2_new,x1_new:x2_new]

roi补正方形:

boxes结构:x1 y1 x2 y2

if t_h>t_w:width = t_hx_min=max(0,(boxes[0]+boxes[2])*0.5-width*0.5)x_max=min(frame.shape[1],(boxes[0]+boxes[2])*0.5+width*0.5)boxes[0],boxes[2]=x_min,x_maxelse:width = t_wy_min = max(0, (boxes[1] + boxes[3]) * 0.5 - width * 0.5)y_max = min(frame.shape[0], (boxes[1] + boxes[3]) * 0.5 + width * 0.5)boxes[1], boxes[3] = y_min, y_max

图片补正方形方法1:

        img = cv2.imread(file)t_h,t_w=img.shape[:2]a_w=max(t_w,t_h)img_b=np.zeros((a_w,a_w,3),dtype=np.uint8)if t_h > t_w:img_b[:,(t_h -t_w)//2:t_w+(t_h -t_w)//2,:]=imgelse:img_b[(t_w-t_h )//2:t_w+(t_w-t_h)//2,:,:]=img

图片补正方形copyMakeBorder:

img_a = cv2.imread(file)if img_a is None:continueheight,width=img_a.shape[:2]if width > height:img_a = cv2.copyMakeBorder(img_a, (width - height) // 2, (width - height) // 2, 0, 0, cv2.BORDER_CONSTANT,value=[255, 255, 255])else:img_a = cv2.copyMakeBorder(img_a, 0, 0, -(width - height) // 2, -(width - height) // 2, cv2.BORDER_CONSTANT,value=[255, 255, 255])aaaa=(max(height,width)//32+1)*32img_o = cv2.resize(img_a, (aaaa, aaaa))img = cv2.cvtColor(img_o, cv2.COLOR_BGR2RGB)

图像补成4的倍数:

import cv2
import numpy as np
if __name__ == '__main__':image=cv2.imread(r'F:\jishui\t01e3bc36f832838c92.jpg')h , w =image.shape[:2]beishu=4if h%beishu>0 or w%beishu>0:new_h = h + beishu - h % beishunew_w = w + beishu - w % beishuimg_b = np.zeros((new_h, new_w, 3), dtype=np.uint8)img_b[:h, :w] = imagecv2.imshow("new_img",img_b)cv2.waitKey()

python 矩形补正方形相关推荐

  1. Python 之vim编写python自动补全

    Pydiction :vim - python自动补全插件 插件的安装如下: 1.下载插件包 https://github.com/vim-scripts/Pydiction 可以直接下载,也可git ...

  2. python 字符串补齐

    python 字符串补全填充固定长度(补齐)的三种方法 text justification 补零,也可以补别的: ''' 原字符串左侧对齐, 右侧补零: ''' str.ljust(width,'0 ...

  3. python自动补全库_叼炸天的库! 自动补全 Python 代码,能节省 60% 敲码时间

    近日,Reddit 上的一篇帖子引起了网友的热议.帖子作者「mlvpj」称: 「我们使用深度学习完成了一个简单的项目,可以自动进行 Python 代码补全.」 根据介绍,该项目基于 LSTM 模型,训 ...

  4. centos7 python tab补全

    centos7 python tab补全 1.编写tab.py [vagrant@node100 ~]$ cat tab.py #!/usr/bin/python # python startup f ...

  5. python自动补全库_这个库厉害了,自动补全Python代码,节省50%敲码时间

    近日,Reddit 上的一篇帖子引起了网友的热议.帖子作者「mlvpj」称: 「我们使用深度学习完成了一个简单的项目,可以自动进行 Python 代码补全.」 根据介绍,该项目基于 LSTM 模型,训 ...

  6. python 插补数据_python 2020中缺少数据插补技术的快速指南

    python 插补数据 Most machine learning algorithms expect complete and clean noise-free datasets, unfortun ...

  7. python安装插件报错原因_Sublime Text3 python自动补全问题——Sublime Text3安装Anaconda插件...

    学习python的时候 在编辑器的选择上会有很多选择,我最终还是选择了sublime text3. 相对于其他编辑器,sublime text有以下特性: 插件多,类似GoSublime,Emmet信 ...

  8. vim python补全_转:VIM python 自动补全插件:pydiction

    这是一个相当不错的 Python 代码自动完成的脚本. 可以实现下面python代码的自动补全: 简单python关键词补全 python 函数补全带括号 python 模块补全 python 模块内 ...

  9. python编程一个正方体的代码_Linux Shell经典面试题之请用shell或Python编写一个正方形(square.sh),接受用户输入的数字...

    Linux Shell经典面试题 1.请用shell或Python编写一个正方形(square.sh),接受用户输入的数字. [root@oldboy ~]# sh square1.sh Please ...

最新文章

  1. MagicDraw UML 16.8 安装教程
  2. 声学漫谈之七:扬声器等效电路与参数
  3. 2021阿里云开发者大会|【云原生数据库:一站式数据服务】分论坛即将开启
  4. 查询hive表_大数据中Hive与HBase的区别与联系
  5. WEB安全基础-XSS基础
  6. 对抗机器学习(Adversarial Machine Learning)发展现状
  7. [erlang]erlang程序运行的几种方式
  8. 阿呆做网站(1)--基本功能
  9. linux之chattr命令
  10. Chrome浏览器 js 关闭窗口失效解决方法
  11. elementui如何在input 框中搜索_【挑战自学Python编程】第八天:while循环以及input()函数...
  12. 泛型编程基础知识详解
  13. echart改变折线图和折线点的颜色以及折线点的大小
  14. 人工智能的示例——八皇后问题
  15. Python生成图文并茂PDF报告
  16. 全志A40I开发板方案定制开发
  17. 在Windows和macOS上更新Node.js到最新版本
  18. Mybatis(1)——Mybatis Generator自动生成代码
  19. GBase8s数据库GET DIAGNOSTICS 语句
  20. 基于 Traefik 的激进 TLS 安全配置实践

热门文章

  1. mysql 5.7.17远端登陆_Mysql 5.7.17安装后登录mysql的教程
  2. mysql connector bin_mysql-connector-java-xxx-bin.jar包的使用
  3. java安装_Java开发中更多常见的危险信号
  4. 小学计算机组成的说课PPT,小学信息技术说课课件
  5. mysql 删除重复索引_如何检查mysql的重复索引
  6. clickhouse 同步mysql_ClickHouse和他的朋友们(9)MySQL实时复制与实现
  7. 创意留言墙图片_年会攻略2|创意合影墙、特色文化墙,有点意思启动仪式,继续玩出彩!!...
  8. 皮一皮:落伍了落伍了
  9. Kafka 2.8.0发布,与ZooKeeper正式分手!
  10. 皮一皮:有这样的妈妈挺有趣的...