I have an image and
1)I get rows and derivative image with using sobel
2)Than I found gradient value
3)I found neighbor coordinates
4)I want to find neighbor coordinates pixel value but I cant do it I use intensity but I cant get a result Here is my code
int main() {
int scale = 1, delta = 0, ddepth = CV_16S,col=0;
Mat img = imread("a.jpg"),newimg;
vector<Mat> line;
vector<Mat>line2;
vector<Point> xmin,xmax,ymin,ymax;//Komşu noktalar için vektörler
for (int i = 0; i < img.rows; i++)
{
line.push_back(img.row(i));
GaussianBlur(line[i],line[i], Size(5, 5), 0, 0, BORDER_DEFAULT);
/// Convert it to gray
cvtColor(line[i], line[i], CV_BGR2GRAY);
/// Generate grad_x and grad_y
Mat grad_x, grad_y;
Mat abs_grad_x, abs_grad_y;
/// Gradient X
//Scharr( src_gray, grad_x, ddepth, 1, 0, scale, delta, BORDER_DEFAULT );
Sobel(line[i], grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT);
double minx, maxx;
Point minloc,maxloc;
minMaxLoc(grad_x, &minx, &maxx, &minloc, &maxloc);
// cout <<i<<". Satir: "<<"Min Loc: "<<minloc<<"->Deger: "<<minx <<" Max Loc: "<<maxloc<<"->Deger: "<<maxx<<endl;
if(minloc.x==0&&minloc.y==0)
{
xmin.push_back(Point(0,0));
xmax.push_back(Point(0,0));
}
else
{
xmin.push_back(Point(minloc.x-1,minloc.y));
xmax.push_back(Point(maxloc.x+1,maxloc.y));
}
cout<<"Xsol komsu: "<<xmin[i]<<"-"<<"Xsag komsu: "<<xmax[i]<<endl;
// Scalar intensity = img.at<uchar>(xmin[i], xmax[i]);
Scalar intensity = img.at<uchar>(Point(xmin[i], xmax[i]));
cout<<intensity<<endl;
// img.at<uchar>(&minloc,&maxloc);
convertScaleAbs(grad_x, abs_grad_x);
Sobel(line[i], grad_y, ddepth, 0, 1, 3, scale, delta, BORDER_DEFAULT);
convertScaleAbs(grad_y, abs_grad_y);
}
Aucun commentaire:
Enregistrer un commentaire