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

网站建设模板购买免费建网站的步骤

网站建设模板购买,免费建网站的步骤,蓝潮网站建设,网站建设中的问题文章目录 1. txt读写读综合案例 日志文件读写 2. excel读写读取csv读取xlsx 3. matplotlib 案例折线图多个折现图散点图柱状图饼状图 4 opencv 案例加载与展示图片缩放图片旋转图片保存图片读取摄像头视频保存opencv 综合案例 5 pickle 案例 1. txt读写 读 file.read() file.r… 文章目录 1. txt读写读综合案例 日志文件读写 2. excel读写读取csv读取xlsx 3. matplotlib 案例折线图多个折现图散点图柱状图饼状图 4 opencv 案例加载与展示图片缩放图片旋转图片保存图片读取摄像头视频保存opencv 综合案例 5 pickle 案例 1. txt读写 读 file.read() file.readlines() file.readline() # # 使用 read 方法读取文件的所有内容 with open(resources/training_log.txt, r) as file:content file.read()print(content)# 使用 readline 方法逐行读取文件 with open(.\\resources/training_log.txt, r) as file:line file.readline()# print(line)while line:print(line, end)line file.readline()# 使用 readlines 方法读取文件的所有行 with open(.\\resources/training_log.txt, r) as file:lines file.readlines()# print(lines)for line in lines:print(line, end)## 写f.write()f.writelines()python # 使用 write 方法写入文件 # with open(resources/example_1.txt, w) as file: # file.write(Hello, World!)# 使用 writelines 方法写入文件 lines [Hello, World!, Welcome to Python programming.] with open(resources/example_2.txt, w) as file:file.writelines(line \n for line in lines)综合案例 日志文件读写 f.write 写一段代码模拟生成accuracy逐步上升、loss逐步下降的训练日志并将日志信息记录到 training_log.txt中 import randomepoch 100 accuracy 0.5 loss 0.9with open(training_log.txt, w) as f:f.write(Epoch\tAccuracy\tLoss\n)for epoch_i in range(1, epoch1):accuracy random.uniform(0, 0.005)loss - random.uniform(0, 0.005)accuracy min(1, accuracy)loss max(0, loss)f.write(f{epoch_i}\t{accuracy:.3f}\t{loss:.3f}\n)print(fEpoch:{epoch_i}, Accuracy:{accuracy}, Loss:{loss}) 2. excel读写 读取csv pd.read_csv() 读取xlsx pd.read_excel() 3. matplotlib 案例 折线图 import numpy as np import matplotlib.pyplot as plt# 创建一个x值的数组从-2π到2π步长为0.01 x np.arange(-2 * np.pi, 2 * np.pi, 0.01)# 计算每个x值对应的sin(x)值 y np.sin(x)# 使用matplotlib来绘制图像 plt.figure() # 创建一个新的图像窗口 plt.plot(x, y) # 绘制折线图 plt.title(sin(x)) # 设置图像的标题 plt.xlabel(x) # 设置x轴的标签 plt.ylabel(sin(x)) # 设置y轴的标签 plt.grid(True) # 显示网格 plt.show() # 显示图像##读取YOLO数据后画出曲线图 import pandas as pd import matplotlib.pyplot as pltdata_loc rresources/yolov5s.csvdata pd.read_csv(data_loc, index_col0)train_bbox_loss data[ train/box_loss]x_list [i for i in range(len(train_bbox_loss))] plt.plot(x_list, train_bbox_loss) plt.xlabel(Epoch) plt.ylabel(Loss) plt.title(YOLOv5s) plt.show()多个折现图 import pandas as pd import matplotlib.pyplot as pltfile_1_loc ./resources/yolov5l.csv file_2_loc C:\WORK\xuxiu\learn\AI\class\【0】源码PDF课件电子书\【0】源码PDF课件电子书\源码PDF课件\第3周资料\第三周课程代码\代码\3.matplotlib_demos\resources\yolov5m.csv file_3_loc ./resources/yolov5s.csvfile_1 pd.read_csv(file_1_loc) file_2 pd.read_csv(file_2_loc) file_3 pd.read_csv(file_3_loc)file_1_train_box_loss file_1[ train/box_loss] file_2_train_box_loss file_2[ train/box_loss] file_3_train_box_loss file_3[ train/box_loss]x_list [i for i in range(len(file_1_train_box_loss))]plt.plot(x_list, file_1_train_box_loss) plt.plot(x_list, file_2_train_box_loss) plt.plot(x_list, file_3_train_box_loss)plt.xlabel(Epoch) plt.ylabel(Loss) plt.title(Train box_loss) plt.grid()plt.legend([yolov5l, yolov5m, yolov5s])plt.show() 散点图 plt.scatter 柱状图 plt.bar plt.bar(x, values, color‘blue’, align‘center’, alpha0.7) 饼状图 plt.pie(sizes, explodeexplode, labelslabels, colorscolors, autopct‘%1.1f%%’, shadowTrue, startangle140) import matplotlib.pyplot as plt# 数据 sizes [15, 30, 45, 10] # 各部分的大小 labels [A, B, C, D] # 各部分的标签 colors [gold, yellowgreen, lightcoral, lightskyblue] # 各部分的颜色 explode (0.1, 0, 0, 0) # 突出显示第一个部分# 绘制扇形图 plt.pie(sizes, explodeexplode, labelslabels, colorscolors, autopct%1.1f%%, shadowTrue, startangle140)# 设置为等比例这样扇形图就是一个圆 plt.axis(equal)# 显示图像 plt.show() 4 opencv 案例 加载与展示图片 cv2.imread() cv2.imshow() import cv2img_path rresources/food.png# 以彩色模式读取图片 image_color cv2.imread(img_path)# 以灰度模式读取图片 image_gray cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)# 显示图片 cv2.imshow(Color Image, image_color) # cv2.imshow(Grayscale Image, image_gray)# 等待用户按键然后关闭窗口 cv2.waitKey(0) cv2.destroyAllWindows() 缩放图片 cv2.resize() 旋转图片 cv2.rotate() # 使用cv2.rotate()函数旋转图片 rotated_90 cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE) # 顺时针旋转90度 rotated_180 cv2.rotate(image, cv2.ROTATE_180) # 顺时针旋转180度 rotated_270 cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE) # 顺时针旋转270度保存图片 cv2.imwrite() import cv2# 读取图像 image cv2.imread(resources/food.png)# 如果图像不为空则保存图像 if image is not None:cv2.imwrite(output_image.png, image) else:print(无法读取图像)读取摄像头 cv2.VideoCapture import cv2# 创建一个 VideoCapture 对象参数 0 表示使用默认的摄像头, 也可以传入一个视频文件的路径 cap cv2.VideoCapture(resources/piano.mp4) # resources/piano.mp4while True:# 读取一帧ret, frame cap.read()# 如果读取成功显示这一帧if ret:cv2.imshow(Frame, frame)# 按 q 键退出循环if cv2.waitKey(15) 0xFF ord(q):break# 释放资源并关闭窗口 cap.release() cv2.destroyAllWindows()释放资源并关闭窗口 cap.release() cv2.destroyAllWindows() 视频保存 cv2.VideoWriter() import cv2# 定义视频捕获对象 cap cv2.VideoCapture(0)# 检查是否成功打开摄像头 if not cap.isOpened():print(Error: Could not open camera.)exit()# 获取摄像头的帧宽度和帧高度 frame_width int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) frame_height int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))# 定义视频编码器和输出文件 fourcc cv2.VideoWriter_fourcc(*mp4v) # 或者使用 XVID out cv2.VideoWriter(output.mp4, fourcc, 20.0, (frame_width, frame_height))while True:ret, frame cap.read()if not ret:print(Failed to grab frame.)break# 将当前帧写入输出视频文件out.write(frame)# 显示当前帧cv2.imshow(frame, frame)# 按q键退出循环if cv2.waitKey(1) 0xFF ord(q):break# 释放资源 cap.release() out.release() cv2.destroyAllWindows()opencv 综合案例 import cv2 import numpy as npdef add_gaussian_noise(image):row, col image.shapemean 0sigma 15gauss np.random.normal(mean, sigma, (row, col))noisy image gaussnoisy_img np.clip(noisy, 0, 255)return noisy_img.astype(np.uint8)# 输入和输出视频文件名 input_video resources/outdoor.mp4 output_video resources/output.mp4# 打开输入视频 cap cv2.VideoCapture(input_video)# 获取视频的帧率和帧大小 fps int(cap.get(cv2.CAP_PROP_FPS)) frame_width int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) frame_height int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))# 计算新的帧大小 (540p) new_height 540 new_width int((new_height / frame_height) * frame_width)# 创建视频写入对象 fourcc cv2.VideoWriter_fourcc(*mp4v) out cv2.VideoWriter(output_video, fourcc, fps, (new_width, new_height), isColorFalse)while True:ret, frame cap.read()if not ret:break# 调整帧大小frame cv2.resize(frame, (new_width, new_height))# 转换为灰度图像frame cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)# 垂直翻转画面frame cv2.flip(frame, 1)# 添加高斯噪声frame add_gaussian_noise(frame)# 写入输出视频out.write(frame)# 释放资源 cap.release() out.release() cv2.destroyAllWindows() 5 pickle 案例 # 使用 pickle 保存数据 with open(data.pkl, wb) as file:pickle.dump(data, file)# 使用 pickle 加载数据 with open(data.pkl, rb) as file:loaded_data pickle.load(file)
http://www.w-s-a.com/news/142390/

相关文章:

  • 做物流的可以在那些网站找客户男生晚上正能量你懂我意思
  • 宁德市城乡住房建设厅网站教育机构logo
  • 做定制网站价格有网站了怎么做app
  • 做网站和制作网页的区别北京朝阳区最好的小区
  • 网站策划 ppt北京装修公司排名推荐
  • 郑州网站建设公司哪家专业好如何注册一家公司
  • 证券投资网站做哪些内容滨州论坛网站建设
  • 重庆网站建设公司模板广东佛山
  • 中展建设股份有限公司网站做网站备案是什么意思
  • 石家庄网站建设接单wordpress功能小工具
  • 有没有专门做网站的网站镜像上传到域名空间
  • 网站建设中 windows买域名自己做网站
  • 设计英语宁波seo做排名
  • 奉贤网站建设上海站霸深圳几个区
  • c#做网站自已建网站
  • 成都地区网站建设网站设计类型
  • 如何做网站结构优化北京响应式网站
  • 出售源码的网站威海住房建设局网站
  • 网站建设补充报价单网站建设 技术指标
  • 做网站费用分摊入什么科目做网络网站需要三证么
  • 房屋备案查询系统官网杭州排名优化软件
  • 网站地图html网络营销的流程和方法
  • 注册好网站以后怎么做wordpress 获取插件目录下
  • 南京做网站dmooo地方网站需要什么手续
  • 网站开发合同有效期omeka wordpress对比
  • 杭州设计网站的公司广州网站改版领军企业
  • 网站备案系统苏州网站设计网站开发公司
  • 怎么样做微网站著名企业vi设计
  • 三分钟做网站网页设计心得体会100字
  • 网站建设支付宝seo建站是什么