问题描述
我所做的是拍摄一张图像,然后通过 openCv 阈值和模糊处理,最后经过水平 Sobel。生成的图像具有我感兴趣的线条。我试图在所有线条周围放置一个矩形,矩形的左上角和矩形的右下角位于从 sobel 看到的第一条线上。我想循环浏览图像并找到左上角和右下角的第一个白色像素,并将其设置为矩形的边界。这个嵌套的 for 循环是我创建的,但它似乎与我对图像的期望不符。
Point botRight=new Point();
outerloop1:
for (double y = img2Height; y>0; y--) {
for (double x =img2Width; x>0; x--) {
if (image1.get((int) x,(int) y)!=null) {
double[] temp=image1.get((int) x,(int) y);
if (temp[0]>1) {
botRight.x=(int)x;
botRight.y=(int)y;
break outerloop1;
}
}
}
}
Point topLeft= new Point();
outerloop1:
for (double y = 25; y<img2Height; y++) {
for (double x =100; x<img2Width; x++) {
if (image1.get((int) x,(int) y);
if (temp[0]==255.0) {
topLeft.x=(int)x;
topLeft.y=(int)y;
break outerloop1;
}
}
}
}
Scalar Box= new Scalar(255,255,0);
Imgproc.rectangle(image2,topLeft,botRight,Box);
如何确保我正确访问像素并评估它是白色还是黑色?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)