当前位置:网站首页>【故障诊断】cv2.imwrite无法写入图片,但程序就是不报错
【故障诊断】cv2.imwrite无法写入图片,但程序就是不报错
2022-06-22 04:39:00 【鲤鱼王的成长之路】
故障现象
在这种故障里,我们发现,使用cv2.imwrite的时候,明明程序不报错,可是在指定的路径下就是找不到生成的图片。
原因解释
这种情况一般是路径不对,因为cv2的这个方法从一开始就没有创建路径的功能。所以即使路径是错的,他也不会管,而是照常执行。
解决方案
创建目录
利用os.path.exists方法加入一个逻辑,如果这个路径不存在,那么就创建这个目录。具体做法可以直接百度,难度不是很大。
检查混用
cv2.imwrite(save_dir_file + '/' + str(f'{
patient_id}_{
stain_type}_{
cord[0] // downsample_factor}_{
cord[1] // downsample_factor}.png'),cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
注意这一行代码是可以执行的,因为save_dir_file是一个字符串数据类型,所以后面是使用加号相连。但是,如果这是一个Path类实例化后的对象,就必须使用反斜杠/直接相连,而不是采用字符串拼接的方式,最后再把Path对象转化为str类型。这一点一定要注意!
还有,在f‘’的两个引号之间的部分是字符串,这其中{}里如果要用的除号,要用双反斜杠。
边栏推荐
- [从零开始学习FPGA编程-39]:进阶篇 - 语法-硬件模块的单元测试:仿真激励、testbench
- What is a forum virtual host? How to choose?
- 浏览器--常用的搜索操作符大全--使用/实例
- Idea installation and use tutorial
- Circuit board layout and wiring precautions for analog / digital mixed signals
- WPF DataContext 使用(2)
- uwsgi-invalid-request-block-size invalid request block size: 21327 (max 4096)...skip 的解决办法
- 【sdx62】QCMAP_CLI手动拨号操作说明
- JUC - 线程中断与线程等待、唤醒(LockSupport)
- 【sdx12】使用QCMAP_CLI启动WiFi操作说明
猜你喜欢

QML control types: swipeview, pageindicator

With this set of templates, it is easier to play with weekly, monthly and annual reports

Bubble sort

Raspberry pie preliminary use

New chief maintenance personnel for QT project

Network Interview eight part essay of daily knowledge points (TCP, startling group phenomenon, collaborative process)

Overrides vs overloads of methods

After the active RM machine is powered off, RM ha switching is normal. However, the cluster resources cannot be viewed on the yarnui, and the application is always in the accepted state.

How to use dataX to update the data in the downstream Oracle database with the update semantics

WPF DataContext 使用(2)
随机推荐
Is the Guoyuan futures account reliable? How can a novice safely open an account?
tinymce. Init() browser compatibility issue
Design and implementation of ks004 based on SSH address book system
Topological sorting
爬梯子&&卖卖股份的最佳时期(跑路人笔记)
window10无法访问局域网共享文件夹
通过ip如何免费反查域名?
天阳科技-宁波银行面试题【杭州多测师】【杭州多测师_王sir】
有了这几个刷题网站,还愁跳槽不涨薪?
torch DDP Training
POSIX semaphore
Kotlin project reports an error and lacks coroutinecontext dependency
Importbeandefinitionregistrar registers beans with the container
After the active RM machine is powered off, RM ha switching is normal. However, the cluster resources cannot be viewed on the yarnui, and the application is always in the accepted state.
Is it safe to open an account in Guoyuan futures?
Go learning notes
What is a forum virtual host? How to choose?
Quick sort
QML control types: swipeview, pageindicator
Accurate identification of bank card information - smart and fast card binding