擅长:python、mysql、java
<p>如果希望在生成图像文件后立即写入内容,则可以使用<code>os.path.isfile()</code>,该函数根据给定目录中文件的存在返回<code>bool</code>值。</p>
<pre><code>import cv2
import os.path
while not os.path.isfile("myImage.jpg"):
#ignore if no such file is present.
pass
img = cv2.imread("myImage.jpg", 0)
cv2.imwrite("result.jpg", img)
</code></pre>
<p>您还可以参考<a href="https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html#display-image" rel="nofollow">docs</a>了解每个方法和基本图像操作的详细实现。</p>