You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Python精准检测滑动窗口角点的技术问询

滑动窗口角点检测问题

我需要检测滑动窗口的角点,已尝试多种基于Python的算法和项目,但均未达到理想效果。试过的方法包括Otsu阈值+轮廓检测、调整不同阈值设置、修改轮廓近似参数,但效果都不理想。

现有代码

import cv2
from matplotlib import pyplot as plt
import numpy as np
from bisect import bisect_left
from PIL import Image


img = cv2.imread('img2.jpg')

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,127,255,0)


contours,h = cv2.findContours(thresh,cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)


## only draw contour that have big areas
imx = img.shape[0]
imy = img.shape[1]
lp_area = (imx * imy) / 10

for cnt in contours:
    approx = cv2.approxPolyDP(cnt,0.01 * cv2.arcLength(cnt, True), True)

    if len(approx) == 4 and cv2.contourArea(cnt) > lp_area:
        print("rectangle")
        tmp_img = img.copy()
        cv2.drawContours(tmp_img, [approx], -1, (0, 255, 255), 2)
        topleft = (approx[0,0,0],approx[0,0,1])
        bottomright = (approx[2,0,0],approx[2,0,1])
        topright = (approx[3,0,0],approx[3,0,1])
        bottomleft = (approx[1,0,0],approx[1,0,1])
        cv2.circle(tmp_img, topleft, 8, (0, 50, 255), -1)
        cv2.circle(tmp_img, bottomright, 8, (0, 255, 255), -1)
        cv2.circle(tmp_img, topright, 8, (255, 50, 0), -1)
        cv2.circle(tmp_img, bottomleft, 8, (255, 255, 0), -1)
        
     
        cv2.waitKey(0)


cv2.destroyAllWindows()

结果对比

预期结果实际结果原始图片(Img3.jpg)
准确标记滑动窗口的四个角点未能正确识别目标滑动窗口,角点标记位置错误包含待检测滑动窗口的原始场景图像

技术问题

  • 检测滑动窗口的最优方案是什么?
  • 如何改进现有代码以获得更好的检测效果?
  • 当前代码是否具备实用价值?

代码参考自Stack Overflow相关问题

内容的提问来源于stack exchange,提问作者MoriX Mehrdad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 20:08:08