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

如何使用OpenCV-Python提取图像中的红框目标区域

图像处理新手求助:提取图像红框区域技术建议

我是图像处理新手,已经完成图像读取、灰度化(graying)、二值化(binarization)、Canny边缘检测、形态学处理(morphological processing)等基础操作,现寻求提取图像中红框区域的技术建议。

相关处理效果图如下:

  • 红框目标图
  • 原图(original)
  • 灰度图(graying)
  • 二值图(binarization)
  • Canny边缘检测图
  • 形态学处理图

已编写的代码如下:

import cv2
import numpy as np
in_file = r"D:test_cut_2.jpg"
image = cv2.imdecode(np.fromfile(in_file, dtype=np.uint8), -1)
# graying
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Canny edge detection
edges = cv2.Canny(gray, 100, 200)
# binarization
_, binary_image = cv2.threshold(gray, 125, 255, cv2.THRESH_BINARY)
# morphological processing
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5))
dilated = cv2.dilate(binary_image, kernel, iterations=2)
dst = cv2.erode(binary_image, kernel, iterations=2)
cv2.imshow('Original Photo', image)
cv2.imshow('gray photo', gray)
cv2.imshow('Binary Image', binary_image)
cv2.imshow('edges', edges)
cv2.imshow('dst', dst)
cv2.imshow('dilated', dilated)
cv2.waitKey(0)
cv2.destroyAllWindows()

内容的提问来源于stack exchange,提问作者陈大光

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 23:26:06