第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

OpenCV C ++ / Obj-C:高級正方形檢測

OpenCV C ++ / Obj-C:高級正方形檢測

C++
德瑪西亞99 2019-12-10 09:38:11
不久前,我問了一個關(guān)于平方檢測的問題,卡爾菲利普得出了不錯的結(jié)果?,F(xiàn)在,我想更進(jìn)一步,找到邊緣不完全可見的正方形??匆幌逻@個例子:例有任何想法嗎?我正在使用karlphillips代碼:void find_squares(Mat& image, vector<vector<Point> >& squares){    // blur will enhance edge detection    Mat blurred(image);    medianBlur(image, blurred, 9);    Mat gray0(blurred.size(), CV_8U), gray;    vector<vector<Point> > contours;    // find squares in every color plane of the image    for (int c = 0; c < 3; c++)    {        int ch[] = {c, 0};        mixChannels(&blurred, 1, &gray0, 1, ch, 1);        // try several threshold levels        const int threshold_level = 2;        for (int l = 0; l < threshold_level; l++)        {            // Use Canny instead of zero threshold level!            // Canny helps to catch squares with gradient shading            if (l == 0)            {                Canny(gray0, gray, 10, 20, 3); //                 // Dilate helps to remove potential holes between edge segments                dilate(gray, gray, Mat(), Point(-1,-1));            }            else            {                    gray = gray0 >= (l+1) * 255 / threshold_level;            }            // Find contours and store them in a list            findContours(gray, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);            // Test contours            vector<Point> approx;            for (size_t i = 0; i < contours.size(); i++)            {                    // approximate contour with accuracy proportional                    // to the contour perimeter                    approxPolyDP(Mat(contours[i]), approx, arcLength(Mat(contours[i]), true)*0.02, true);                    // Note: absolute value of an area is used because                    // area may be positive or negative - in accordance with the                    // contour orientation                    }            }        }    }}
查看完整描述

3 回答

?
青春有我

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個贊

我嘗試使用convex hull method它非常簡單。


在這里,您可以找到檢測到的輪廓的凸包。它消除了紙張底部的凸度缺陷。


下面是代碼(在OpenCV-Python中):


import cv2

import numpy as np


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

img = cv2.resize(img,(500,500))

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)


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

contours,hier = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)


for cnt in contours:

    if cv2.contourArea(cnt)>5000:  # remove small areas like noise etc

        hull = cv2.convexHull(cnt)    # find the convex hull of contour

        hull = cv2.approxPolyDP(hull,0.1*cv2.arcLength(hull,True),True)

        if len(hull)==4:

            cv2.drawContours(img,[hull],0,(0,255,0),2)


cv2.imshow('img',img)

cv2.waitKey(0)

cv2.destroyAllWindows()

(在這里,我并沒有在所有平面上都找到正方形。如果需要,可以自己做。)



查看完整回答
反對 回復(fù) 2019-12-10
  • 3 回答
  • 0 關(guān)注
  • 706 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號