the output u can see over there the edges on some of the window are discontinued which i need to detect and draw contour because of the tree being overlaid on them . #include
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(){
Mat input=imread("C:/Users/manjswa2/Downloads/Basic_Linear_Transform_Tutorial_gamma_correction.jpg");
Mat lookUpTable(1, 256, CV_8U);
uchar* p = lookUpTable.ptr();
for (int i = 0; i < 256; ++i)
p[i] = saturate_cast<uchar>(pow(i / 255.0, 0.8) * 255.0);
Mat res = input.clone();
LUT(input, lookUpTable, res);
Mat imagray,edgeout,fout,edgeout1;
cvtColor(res,imagray,COLOR_RGB2GRAY);
GaussianBlur(res,fout,Size(3,3),0);
Canny(imagray,edgeout,150,200);
Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));
morphologyEx(edgeout, edgeout1, MORPH_CLOSE, kernel);
vector<vector> contours;
findContours(edgeout1, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
// draw contours on windows
vector<vector> squares;
for (size_t i = 0; i < contours.size(); i++) {
vector approx;
approxPolyDP(contours[i], approx, arcLength(contours[i], true) * 0.0225,true);
if (approx.size() == 4 && isContourConvex(approx) ) {
double length = arcLength(approx, true);
if (length > 50) { // Adjust the minimum length as per your requirement
squares.push_back(approx);
}
}
}
// Draw contour on the original image
Mat image_copy = res.clone();
drawContours(image_copy, squares, -1, Scalar(0, 255, 0), 2);
imshow("Input",input);
imshow("Cannyopt",edgeout1);
imshow("Final contour",image_copy);
waitKey(0);
return 0;
} this is my code what changes can i make out to get it right