Opencv Python

读取图片

1
2
3
import/export cv2

cv2import.imread('demo.png', )

读取视频

GUI 功能

图片基本操作

  1. 教程
  2. 基本操作示例

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
    import/export numpy as np
    import/export cv2
    
    img = cv2.imread('messi5.jpg',0)
    cv2import.imshow('image',img)
    k = cv2.waitKey(0)
    if k == 27:         # wait for ESC key to exit
        cv2import.destroyAllWindows()
    elif k == ord('s'): # wait for 's' key to save and exit
        cv2import.imwrite('messigray.png',img)
        cv2import.destroyAllWindows()
  3. 图像转换示例

Tmpfile

FAQ

windows 上 NamedTemporaryFile 读取失败 PermissionError

参考:

解决方法:

  1. 设置 NamedTemporaryFile(delete=False)
  2. NamedTemporaryFile 返回的是直接打开的文件,因此删除时需要确保已经关闭

    • f.close()
    • os.unlink(f)

举例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# delete=True, 避免PermissionError
with NamedTemporaryFile(suffix='.html', delete=(False if os.name == 'nt' else True)) as f:

    output_file(f.name, title='TPP 相图')

    plt = draw_plot()
    if show_plot:
        show(plt)

    save(plt)
    content = f.read().decode('utf-8')

if os.name == 'nt':
    try:
        # 先关闭
        f.close()
        # 再删除
        os.unlink(f.name)
    except OSError as e:
        logger.error(e)

return content

Postgresql

Cheatsheat

导出数据库到 .sql 文件

psql 使用指南

参考:

表格
\dtlist tables列出所有表格
\dtable schema
\d+table schema detail
数据库
\l\list databases列举数据库
\l+list databases detail
\h CREATE DATABASEhelp on create database创建帮助
CREATE DATABASE创建
\c <my-db>\connect database连接,切换 db

术语

meta-commands

形如 \dt, \l+ 等的命令就是 meta-commands

Sqlite

命令行使用指南

表格
.tableslist tables
.schematable schema
数据库
.databaseslist databases
select 结果展示
.header on显示表头
.mode column按列展示;列对齐

列出 databese

.databses

列出 table

.tables

table 的信息 schema

.schema <your table>

创建表格

1
2
3
4
5
CREATE TABLE department(
   id INT PRIMARY KEY      NOT NULL,
   dept           CHAR(50) NOT NULL,
   emp_id         INT      NOT NULL
);