Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 角点检测_Opencv_Image Processing - Fatal编程技术网

Opencv 角点检测

Opencv 角点检测,opencv,image-processing,Opencv,Image Processing,我是OpenCV的新手。我试图在相当简单的图像中检测90度角。我需要检测环绕对象的矩形的角。我正在使用shi Thomasi功能。以下是我的代码: for x in range(0, 50): ret, frame = cap.read() # make image gray scale im = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #finding corners corners = cv2.goodFeaturesToTrack(i

我是OpenCV的新手。我试图在相当简单的图像中检测90度角。我需要检测环绕对象的矩形的角。我正在使用shi Thomasi功能。以下是我的代码:

for x in range(0, 50):
    ret, frame = cap.read()

# make image gray scale
im = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 

#finding corners 
corners = cv2.goodFeaturesToTrack(im, 1, 0.01, 10)
corners = np.int0(corners)
for i in corners:
    x, y = i.ravel()
    cv2.circle(frame, (x, y), 3, 255,-1)
cv2.imwrite("DetectedCorners.png", frame)
问题:始终会检测到该对象中的某些角点。我需要一种方法,完全移除那个物体,然后检测角点

我不知道如何移除那个物体。 有什么建议吗?照片显示了我的结果。有时会检测到周围矩形的角点,有时会检测到复杂对象中的一些随机点。
在检测角点之前,我也使用了Canny,但结果差了10倍

>快速、肮脏的C++解决方案,只是为了证明Hough变换用于检测线,然后计算它们的交集。< /P> 如果需要,您最终可以将代码移植到Python

#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
    Mat3b img = imread("path_to_image");

    // Convert to grayscale
    Mat1b gray;
    cvtColor(img, gray, COLOR_BGR2GRAY);

    // Compute edges
    Mat1b edges;
    Canny(gray, edges, 400, 100);

    // Create the output result image
    Mat3b res;
    cvtColor(edges, res, COLOR_GRAY2BGR);

    // Call hough
    vector<Vec2f> lines;
    HoughLines(edges, lines, 1, CV_PI / 180, 200, 0, 0);

    vector<pair<Point,Point>> pts;
    vector<Point> intersections;

    for (size_t i = 0; i < lines.size(); i++)
    {
        float rho = lines[i][0], theta = lines[i][1];

        // Get 2 points on each line
        Point pt1, pt2;
        double a = cos(theta), b = sin(theta);
        double x0 = a*rho, y0 = b*rho;

        pt1.x = cvRound(x0 + 1000 * (-b));
        pt1.y = cvRound(y0 + 1000 * (a));
        pt2.x = cvRound(x0 - 1000 * (-b));
        pt2.y = cvRound(y0 - 1000 * (a));

        // Save the pair of points 
        pts.push_back(make_pair(pt1, pt2));

        // Draw lines
        line(res, pt1, pt2, Scalar(0, 0, 255), 3, CV_AA);
    }

    // for each couple of lines
    for (int i = 0; i < pts.size() - 1; ++i)
    {
        // get the two points of the first line
        const Point&  p1 = pts[i].first;
        const Point&  p2 = pts[i].second;

        for (int j = i + 1; j < pts.size(); ++j)
        {
            // Get the two points of the second line
            const Point&  p3 = pts[j].first;
            const Point&  p4 = pts[j].second;

            // Compute intersection

            Point p;
            float den = (p1.x - p2.x) * (p3.y - p4.y) - (p1.y - p2.y) * (p3.x - p4.x);
            if (den != 0) // if not parallel lines
            {
                p.x = ((p1.x*p2.y - p1.y*p2.x)*(p3.x - p4.x) - (p1.x - p2.x)*(p3.x*p4.y - p3.y*p4.x)) / den;
                p.y = ((p1.x*p2.y - p1.y*p2.x)*(p3.y - p4.y) - (p1.y - p2.y)*(p3.x*p4.y - p3.y*p4.x)) / den;

                // Draw intersection
                circle(res, p, 7, Scalar(0, 255, 0), 2);
            }

            // Save intersections
            intersections.push_back(p);
        }
    }

    return 0;
}
#包括
#包括
使用名称空间cv;
使用名称空间std;
int main()
{
Mat3b img=imread(“路径到图像”);
//转换为灰度
Mat1b灰色;
CVT颜色(img,灰色,颜色为灰色);
//计算边
Mat1b边缘;
Canny(灰色,边缘,400100);
//创建输出结果图像
Mat3b res;
CVT颜色(边缘、分辨率、颜色为灰色2BGR);
//打电话给霍夫
矢量线;
HoughLines(边、线、1、CV_PI/180、200、0、0);
向量pts;
矢量交点;
对于(size_t i=0;i
结果:


难道你不能检测出清晰可见的黑线(例如,使用Hough)然后计算角点作为这些线的交点吗?我尝试使用Hough I,但无法使其精确工作。检测到大量冗余线路。加上一些线不完整,它们彼此不相交。也许是因为我对开放式简历一无所知。如果你能帮助我,我将不胜感激。