Human-written demonstration (OpenAssistant volunteers)· OpenAssistant (human-written)
OpenAssistant Conversations (oasst2)
如何用opencv-python提取图片轮廓?
In OpenAssistant data, “assistant” turns were written by human volunteers as demonstrations. They are not model outputs.
- User
如何用opencv-python提取图片轮廓?
- Assistant
什么是轮廓
轮廓是一系列相连的点组成的曲线,代表了物体的基本外形,相对于边缘,轮廓是连续的,边缘并不全部连续。
提取图片轮廓
可以使用cv2.findContours来提前图片轮廓,具体的实现代码请参考:
import cv2 as cv img = cv.imread("black.png") gray_img = cv.cvtColor(img, cv.COLOR_BGR2GRAY) ret, thresh = cv.threshold(gray_img, 127, 255, 0) contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_NONE) print(len(contours[0]))这段代码先用 threshold() 对图像进行降噪处理,它的原型函数如下:
retval, dst = cv.threshold(src, thresh, maxval, type[, dst] )- dst:结果图像。
- src:原图像。
- thresh:当前阈值。
- maxVal:最大阈值,一般为255。
- type:阈值类型。
查找轮廓使用的函数为 findContours() ,它的原型函数如下:
cv2.findContours(image, mode, method[, contours[, hierarchy[, offset ]]])- image:源图像。
- mode:表示轮廓检索模式。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →