【问题标题】:How can I extract screen from mobile device using OpenCV?如何使用 OpenCV 从移动设备中提取屏幕?
【发布时间】:2019-11-28 07:34:04
【问题描述】:

我想使用 python 从移动设备图片中提取屏幕部分。 我可以得到4边缘或点屏幕部分(我不知道我是否可以得到iphone刘海风格的屏幕)

我认为使用 openCV 似乎可行,但我不知道如何调整它。

如果你能帮忙,请告诉我。

提前谢谢你。

I want to draw green box like this

【问题讨论】:

标签: python opencv extract detect


【解决方案1】:

以下是查找可能对您有用的轮廓的简单示例:

image = cv2.imread('/path/to/your/img.jpg')

# convert the image to grayscale, blur it, and find edges
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
edged = cv2.Canny(gray, 30, 200)

# find contours
_, cnts, _ = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# sort by area and leave only 5 largest
nts = sorted(cnts, key=cv2.contourArea, reverse=True)[:5]  

screenCnt = None

# iterate over contours and find which satisfy some conditions
for c in cnts:
    peri = cv2.arcLength(c, True)
    approx = cv2.approxPolyDP(c, 0.02 * peri, True) # you could tune value of 0.02
    x, y, w, h = cv2.boundingRect(approx)

    if h >= 15 and len(approx) == 4:
        screenCnt = approx
        break

# if found
if screenCnt is not None:
    # draw rect
    x, y, w, h = cv2.boundingRect(screenCnt)
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 3)
    # or draw contour
    cv2.drawContours(image, [screenCnt], -1, (255, 0, 0), 3)
    cv2.imshow("image", image)
    cv2.waitKey(0)

红色 - 近似矩形 蓝色 - 轮廓

【讨论】:

    猜你喜欢
    • 2012-05-06
    • 2015-12-23
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 2021-06-23
    相关资源
    最近更新 更多