![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
davin12
鲁迅说过:“如果人不学习,那和咸鱼有什么区别”。
展开
-
图像特征点匹配及获取匹配坐标
import cv2 as cvimport numpy as npfrom matplotlib import pyplot as pltfrom scipy import statsdef drawMatchesKnn_cv(img1_gray, kp1, img2_gray, kp2, goodMatch): h1, w1 = img1_gray.shape[:2] h2, w2 = img2_gray.shape[:2] vis = np.zeros((max(原创 2021-07-22 22:04:00 · 2547 阅读 · 3 评论 -
module ‘win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x9‘ has no attribute ‘CLSIDToClassMa
使用 win32com 遭遇如下bugTraceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Program Files (x86)\Python37-32\lib\site-packages\win32com\client\gencache.py", line 534, in EnsureDispatch mod = EnsureModule(tla[0], t原创 2021-07-04 20:50:04 · 1646 阅读 · 1 评论 -
self._handle = _dlopen(self._name, mode) OSError: [WinError126] The specified module could not found
做项目的时候,由于需要做dll来提速,但是经常性的爆出errorFile "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 434, in LoadLibrary return self._dlltype(name) File "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.原创 2021-06-29 20:17:44 · 7393 阅读 · 1 评论 -
pyqt5 QImage 转 numpy.ndarray
使用python 的开源库 qimage2ndarrayqimage2ndarray文档from PyQt5 import QtCore, QtGui, QtWidgetsimport sysfrom PyQt5.QtCore import *from PyQt5.QtWidgets import *from PyQt5 import QtWidgetsfrom PyQt5 import QtGuiimport numpy as npimport qimage2ndarrayimport原创 2021-06-27 17:31:37 · 1754 阅读 · 3 评论 -
np.where
np.where 矩阵运算,寻找符合条件的值,并返回带有命中元素的横纵坐标import numpy as npimport cv2 as cvfrom skimage.measure import labelimg = np.zeros((10,10))img[:2,:2] = 1img[3:5,3:5] = 1print(img)labels, num = label(img,background=0,return_num=True,connectivity=2)print(len原创 2021-06-26 16:24:37 · 141 阅读 · 0 评论 -
numpy 计算矩阵中指定元素的个数
import numpy as npimport cv2 as cvimg = np.zeros((200,200)).astype(np.uint8)img[100:200,100:200] = 128img[:100,:100] = 255img[:10,:10] = 9print(np.sum(img==0))cv.imshow('img',img)cv.waitKey()原创 2021-06-26 15:21:02 · 2402 阅读 · 0 评论 -
pyqt5 生成饼图并保存成图片
from PyQt5.QtWidgets import QApplication, QMainWindowimport sysfrom PyQt5.QtChart import QChart, QChartView, QPieSeries, QPieSlicefrom PyQt5.QtGui import QPainter, QPenfrom PyQt5.QtCore import Qtfrom PyQt5 import QtCore,QtGui,QtWidgetsclass Window(原创 2021-06-26 15:10:28 · 1822 阅读 · 0 评论 -
python datetime str类型相互转化 求本月第一天和最后一天 本季度第一天和最后一天
import calendarimport datetimenow = datetime.datetime.now()print(now)now = datetime.datetime.now().date()print(now)now = datetime.date.today()print(now)this_month_start = datetime.datetime(now.year, now.month, 1)print(this_month_start)this_m原创 2021-06-22 19:29:22 · 134 阅读 · 0 评论 -
python matplotlib画出柱状图并保存成图片
import matplotlib.pyplot as pltplt.rcParams['font.sans-serif']=['SimHei'] #显示中文标签plt.rcParams['axes.unicode_minus']=False #这两行需要手动设置# 添加图形属性plt.xlabel('这个是行属性字符串')plt.ylabel('这个是列属性字符串')plt.title('这个是总标题')y = [10, 11, 12, 13, 14, 15, 16, 17, 18原创 2021-06-21 09:16:44 · 4005 阅读 · 0 评论 -
python 更改配置文件 key value 值
import configparserdef set_value_in_property_file(file_path, section, key, value): config = configparser.RawConfigParser() config.read(file_path) config.set(section,key,value) cfgfile = open(file_path,'w') config.write(cfgfile, space_a原创 2021-06-20 14:06:30 · 443 阅读 · 0 评论 -
python 控制浏览器打开网址或者pdf文件 并关闭浏览器
import webbrowserimport oswebbrowser.open('file:///D:test.pdf', new=2)try: # close google chrome os.system("taskkill /im chrome.exe /f")except Exception as e: print(e)try: # close microsoft edge os.system("taskkill /im msedge.exe原创 2021-06-19 16:21:22 · 966 阅读 · 0 评论 -
python 使用openpyxl读写excel 文件
写excelfrom openpyxl import Workbook#创建Workbook,并默认会创建一个空表,名称为:Sheetwb = Workbook()#获取默认的sheetws1 = wb.active#设置Sheet名称ws1.title = 'Sheet1'#写入单个单元格ws1['A1'] = '标题列1'ws1['B1'] = '标题列2'#写入多个单元格(从有数据的行的下一行写入)ws1.append(['张三', 80])ws1.append(['李四'原创 2021-06-18 16:51:00 · 189 阅读 · 0 评论 -
使用graphicsView的完善的画图及保存方案
之前出现GraphicsView画图会出现的问题做了改进,去掉边框以及对位置进行了判断from PyQt5 import QtCore, QtGui, QtWidgetsimport sysfrom PyQt5.QtCore import *from PyQt5.QtWidgets import *from PyQt5 import QtWidgetsfrom PyQt5 import QtGuiclass GraphicsView(QtWidgets.QGraphicsView):原创 2021-06-18 11:22:29 · 837 阅读 · 0 评论 -
python 调用office 软件 excel 打开xlsx文件
import win32com.client as win32from pathlib import Pathout_file = Path.cwd() / "sample.xlsx"excel = win32.gencache.EnsureDispatch('Excel.Application')excel.Visible = True# Open up the fileexcel.Workbooks.Open(out_file)原创 2021-06-16 10:43:24 · 1730 阅读 · 0 评论 -
pyqt5使用Qpainter 指定pdf文件进行打印
import osimport sysfrom PIL.ImageQt import ImageQtfrom PyQt5 import QtWidgetsfrom PyQt5.QtCore import QSize, Qtfrom PyQt5.QtGui import QPainterfrom PyQt5.QtPrintSupport import QPrintDialog, QPrinterfrom PyQt5.QtWidgets import QMainWindow, QFileDial原创 2021-06-05 21:07:32 · 832 阅读 · 0 评论 -
使用fpdf生成实验报告,带表格和图片
#!/usr/bin/env python# -*- coding: utf8 -*-from fpdf import FPDFpath = "D:/collect2.png"pdf = FPDF(format='letter',unit='cm')pdf.add_page()pdf.set_top_margin(2.54)pdf.set_left_margin(2.18)pdf.ln(2)pdf.add_font('fireflysung', '', 'Font/fireflys原创 2021-06-05 20:11:11 · 587 阅读 · 0 评论 -
解决 python fpdf 字体问题 AttributeError: ‘FPDF‘ object has no attribute ‘unifontsubset‘
if self.unifontsubset and isinstance(txt, str) and not PY3K:AttributeError: ‘FPDF’ object has no attribute ‘unifontsubset’使用python 的fpdf 想生成pdf文档,可是不可避免地就会遇到中文不兼容的问题,这是因为fpdf官方库中的字体很少,这也是它占用内存小的原因。为此,我下载了fireflysung.ttf 并添加字体后完美解决from fpdf import FPDF原创 2021-06-05 15:35:30 · 2000 阅读 · 2 评论 -
python fpdf中multi_cell实现自动换行
# Import FPDF classfrom fpdf import FPDF# Create instance of FPDF class# Letter size paper, use inches as unit of measurepdf=FPDF(format='letter', unit='in')# Add new page. Without this you cannot create the document.pdf.add_page()# Remember to a原创 2021-06-05 13:15:48 · 1326 阅读 · 0 评论 -
python写入pdf文件
import pandas as pdimport matplotlibfrom pylab import title, figure, xlabel, ylabel, xticks, bar, legend, axis, savefigfrom fpdf import FPDFdf = pd.DataFrame()df['Question'] = ["Q1", "Q2", "Q3", "Q4"]df['Charles'] = [3, 4, 5, 3]df['Mike'] = [3, 3,原创 2021-06-02 15:00:07 · 1893 阅读 · 0 评论 -
pyqt5 qtchart 画出饼图
from PyQt5.QtWidgets import QApplication, QMainWindowimport sysfrom PyQt5.QtChart import QChart, QChartView, QPieSeries, QPieSlicefrom PyQt5.QtGui import QPainter, QPenfrom PyQt5.QtCore import Qtclass Window(QMainWindow): def __init__(self):原创 2021-06-01 20:40:25 · 2927 阅读 · 6 评论 -
pyqt5使用qtchart画柱状图
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayoutfrom PyQt5.QtChart import QChart, QChartView, QBarSet, \ QPercentBarSeries, QBarCategoryAxisimport sysfrom PyQt5.QtGui import QIconclass Window(QWidget): def __init__(self):原创 2021-06-01 20:14:38 · 3247 阅读 · 1 评论 -
python根据端口名称获取端口号
portName = "USB-SERIAL CH340"import serial.tools.list_portsport_list = list(serial.tools.list_ports.comports())print(port_list)if len(port_list) == 0: print('无可用串口')else: for i in range(0,len(port_list)): print(port_list[i]) pri原创 2021-05-27 13:37:19 · 543 阅读 · 0 评论 -
python skimage.measure.label标记不同连通域
python 的skimage库中的measure.label可用于标记不同连通域,从而方便图像分析skimage.measure.label(label_image, background=None, return_num=False, connectivity=None)源码如下:@deprecate_kwarg({"input": "label_image"}, removed_version="1.0")def label(label_image, background=None, ret原创 2021-04-27 19:48:15 · 4340 阅读 · 0 评论 -
python在图上画出射线及平行线
import mathimport numpy as npimport cv2 as cvdef Polar2Cartesian(theata): """ 极坐标转直角坐标系 :return: 斜率 """ pi = 3.14 radian = pi * theata / 180 return math.tan(radian)def Painter(ori,theta): """ painter a picture原创 2021-04-25 18:53:01 · 2333 阅读 · 0 评论 -
pyqt5 GraphicsView 加载图片 鼠标托画填充路径并保存成图片
本文仅供记录,各位如有参考,不胜荣幸解决之前临时变量销毁导致的程序奔溃,使用成员变量定义from PyQt5 import QtCore, QtGui, QtWidgetsimport sysfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *from PyQt5 import QtWidgetsfrom PyQt5 import QtGuiclass GraphicsView(原创 2021-04-21 21:42:33 · 825 阅读 · 0 评论