如何检测图像宽度

问题描述 投票:0回答:1

我必须编写程序以检测物体的宽度。我知道没有参考对象,它将以像素表示,但对我来说已经足够了。背景将始终为白色。我有我现在应该做什么的问题。

我将竭尽全力为您提供帮助!enter image description here

import numpy as np
import imutils
import cv2
import math

# Function to show array of images (intermediate results)
def show_images(images):
    for i, img in enumerate(images):
        cv2.imshow("image_" + str(i), img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


# Read image and preprocess
image = cv2.imread('44.jpg')

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (9, 9), 0)

edged = cv2.Canny(blur, 50, 100)
edged = cv2.dilate(edged, None, iterations=1)
edged = cv2.erode(edged, None, iterations=1)

show_images([blur, edged])

#show_images([cnts, edged])
python python-3.x opencv opencv3.1
1个回答
0
投票

欢迎使用堆栈溢出!

由于您使用的是OpenCV,因此查找图像尺寸就像下面的代码一样简单。

import numpy as np
import cv2

img = cv2.imread('image.png')

dimension = img.shape


height = img.shape[0]
width = img.shape[1]
channels = img.shape[2] 

阅读有关此here的更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.