How to get the pixel coordinates of 4 corners points of (quasi) rectangle in image?
I would like to find the pixel coordinates of the 4 corner points of the detected rectangle (its a airplane window that I assume is rectangle). Im able to detect the window (the rectangle) as shown in the image but then do not know how to get the pixel coordinates of the 4 rectangle corner points. I think they can be detected by harris corner , right? Then can store coordinates of corner points in matrix S?
here the code
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<dirent.h>
#include<string.h>
using namespace cv;
using namespace std;
Mat src; Mat src_gray;
int thresh = 5;
int max_thresh = 60000;
RNG rng(12345);
const char* source_window = "Source image";
const char* corners_window = "Corners detected";
//int thresh = 1;
//int max_thresh = 300;
//void thresh_callback(int, void* );
static double angle(Point pt1, Point pt2, Point pt0)
{
double dx1 = pt1.x - pt0.x;
double dy1 = pt1.y - pt0.y;
double dx2 = pt2.x - pt0.x;
double dy2 = pt2.y - pt0.y;
return (dx1*dx2 + dy1*dy2)/sqrt((dx1*dx1 + dy1*dy1)*(dx2*dx2 + dy2*dy2) + 1e-10);
}
void setLabel(cv::Mat& im, const std::string label, std::vector<cv::Point>& contour)
{
int fontface = cv::FONT_HERSHEY_SIMPLEX;
double scale = 0.4;
int thickness = 1;
int baseline = 0;
cv::Size text = cv::getTextSize(label, fontface, scale, thickness, &baseline);
cv::Rect r = cv::boundingRect(contour);
cv::Point pt(r.x + ((r.width - text.width) / 2), r.y + ((r.height + text.height) / 2));
cv::rectangle(im, pt + cv::Point(0, baseline), pt + cv::Point(text.width, -text.height), CV_RGB(255,255,255), CV_FILLED);
cv::putText(im, label, pt, fontface, scale, CV_RGB(0,0,0), thickness, 8);
}
int main(int argc,char** argv)
{
IplImage *desimg,*srcimg;
string dirName = "C:/B787/" "/";
DIR *dir;
dir = opendir(dirName.c_str());
string imgName;
struct dirent *ent;
if (dir != NULL) {
while ((ent = readdir (dir)) != NULL) {
imgName= ent->d_name;
if(imgName.compare(".")!= 0 && imgName.compare("..")!= 0)
{
string aux;
aux.append(dirName);
aux.append(imgName);
cout << aux << endl;
Mat image= imread(aux);
//imshow(aux,image);
waitKey(0);
//resize(image, image, Size(640,480), 0, 0, INTER_CUBIC);
//char* source_window = "Source";
//namedWindow( source_window, CV_WINDOW_AUTOSIZE );
//imshow( source_window, image );
//================================
Mat gray,bw,dil,erd, dst_final;
//cv::GaussianBlur(image, src_gray, cv::Size(9, 9), 2, 2); //original
//cv::GaussianBlur(image, src_gray, cv::Size(3,3), 1,1,BORDER_DEFAULT); //original
cv::GaussianBlur(image, src_gray, cv::Size(3,3),1,1,BORDER_DEFAULT); //original
medianBlur(image, src_gray, 11);
blur( image, src_gray, Size(3,3) );
cvtColor(src_gray,gray,CV_BGR2GRAY);
//cvtColor( src, src_gray, COLOR_BGR2HSV );
//blur( src_gray, gray, Size(1,3) );
//medianBlur(src, src_gray,, 5);
Canny(gray,bw,600,1200,5,true);
//Canny(gray,bw,1200,600,5,true);
//Canny(gray,bw,thresh, thresh*1, 5,true);
//Canny( src_gray, canny_output, thresh, thresh*1, 3 );
//dilate(bw,dil,Mat());
//erode(dil,erd,Mat());
//Mat tmp=bw.clone();
//cvtColor( src, src_gray, COLOR_BGR2GRAY);
//blur( src_gray, src_gray, Size(1,3) );
// medianBlur(src_gray, src_gray, 3);
//cv::GaussianBlur(src_gray, src_gray, cv::Size(9, 9), 2, 2);
/////////Mat gray ...