opencv 如何在Colab Editor中调整CV2图像的大小

gojuced7  于 2023-06-24  发布在  其他
关注(0)|答案(2)|浏览(122)

我试图在Colab编辑器的cv 2中调整图像大小,但我得到以下错误。谁能帮我调试这个错误?
我的代码:

img= cv2.imread("/content/drive/My Drive/DL_DATAset/Autotag/Test Image/image100.jpg")
height = 220
width = 220
dim = (width, height)
res = cv2.resize(img, dim, interpolation=cv2.INTER_LINEAR)

错误:
错误:OpenCV(4.1.2)/io/opencv/modules/imgproc/src/resize.cpp:3720:错误:(-215:Assert失败)!ssize.empty()in function 'resize'

qcuzuvrc

qcuzuvrc1#

该错误只是意味着无法加载/读取图像。是从这条线传来的

img= cv2.imread("/content/drive/My Drive/DL_DATAset/Autotag/Test Image/image100.jpg")
    • 路径:镜像应该在工作目录下,或者给出镜像的完整路径。**

您确定提供了imgread()方法的正确路径吗?尝试给它一个完整的绝对路径,例如。

img= cv2.imread("'C:\Users\User\Desktop\geeksforgeeks.png'")
dbf7pr2w

dbf7pr2w2#

要解决这个问题,你可以这样做

docs="""yourstring""".split("\n")

docs

w_corp = 0
w_oracle = 0
w_both = 0
for s in docs:
  s_splited = s.split(" ")
  if "ex1" in s_splited:
    w_corp += 1

  if "ex2" in s_splited:
    w_oracle += 1

  if "ex1" in s_splited and "ex2" in s_splited:
    w_both += 1

import math
max(0, math.log2(len(docs) * w_both / (w_oracle * w_corp)))

import cv2

img = cv2.imread("picture.jpg")

img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

img_shape = img_rgb.shape[:2]

img_shape

k = 3934 / 1967
k

new_h = 5893 / k
new_h

img_resized = cv2.resize(img_rgb, (1967, int(new_h)), interpolation = cv2.INTER_AREA) 
img_resized.shape

k = 3934 / 5893 
k

import matplotlib.pyplot as plt

a,_,_=plt.hist(img_resized[:, :, 0].ravel(), bins = 256,density=True)
b,_,_=plt.hist(img_resized[:, :, 1].ravel(), bins = 256,density=True)
c,_,_=plt.hist(img_resized[:, :, 2].ravel(), bins = 256,density=True)

max(a.max(), b.max(), c.max())

相关问题