Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
C++ 如何使用opencv从图像中查找标尺位置?_C++_Opencv_Pixel - Fatal编程技术网

C++ 如何使用opencv从图像中查找标尺位置?

C++ 如何使用opencv从图像中查找标尺位置?,c++,opencv,pixel,C++,Opencv,Pixel,我必须使用opencv从图像中找到标尺的位置。我能够检测到标尺的颜色(绿色)。如何读取图像中的所有像素并获得标尺的上下位置 void findrulerPosition(cv::Mat image, int indx) { std::stringstream ss;//create a stringstream ss << indx;//add number to the stream cv::Mat hsv; cvtColor(image, hsv, CV_BGR2HSV);

我必须使用opencv从图像中找到标尺的位置。我能够检测到标尺的颜色(绿色)。如何读取图像中的所有像素并获得标尺的上下位置

void findrulerPosition(cv::Mat image, int indx) {
std::stringstream ss;//create a stringstream
ss << indx;//add number to the stream

cv::Mat hsv;
cvtColor(image, hsv, CV_BGR2HSV);

String filename = OUTPUT_FOLDER + "hsv" + ss.str() + ".png";
imwrite(filename, hsv );

cv::Mat hsvbw;
inRange(hsv, cv::Scalar(30,0,0), cv::Scalar(80, 255, 255), hsvbw);
//inRange(hsv, cv::Scalar(12,255,255), cv::Scalar(23, 245, 255), hsvbw);
   //inRange(image, cv::Scalar(0,64,255), cv::Scalar(0, 207, 255), hsvbw);

filename = OUTPUT_FOLDER + "hsvbw" + ss.str() + ".png";
imwrite(filename, hsvbw );


vector<vector<Point> > contours;
findContours(hsvbw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
cv::Mat dst = Mat::zeros(image.size(), image.type());
drawContours(dst, contours, -1, Scalar::all(255), CV_FILLED);

this->cmpddst &=  dst;
dst &= image;
this->cmpddst &=  image;

filename = OUTPUT_FOLDER + "cmpddst" + ss.str() + ".png";
imwrite(filename, this->cmpddst );


filename = OUTPUT_FOLDER + "dst" + ss.str() + ".png";
imwrite(filename, dst );
void findrulerPosition(cv::Mat image,int indx){
std::stringstream ss;//创建一个stringstream
ss cmpddst&=dst;
dst&=图像;
此->cmpddst&=图像;
filename=OUTPUT_FOLDER+“cmpddst”+ss.str()+“.png”;
imwrite(文件名,this->cmpddst);
filename=OUTPUT_FOLDER+“dst”+ss.str()+“.png”;
imwrite(文件名,dst);
}以下是我所做的:

  • 稍微改善了你的绿色范围,因为你的不是检测绿色,而是检测许多其他颜色
  • 找到图像上的轮廓
  • 查找面积大于100的等高线
  • 找到轮廓的上下点
  • 画这两点
  • matsrc=imread(“input.png”),tmp;
    CVT颜色(src、tmp、CV_BGR2HSV_FULL);
    范围(tmp,标量(50,50,50),标量(70255,255),tmp);
    矢量等值线;
    findContours(tmp、等高线、等高线图、等高线图、等高线链图、等高线图);
    int upY=int_MAX,lowY=0,upX,lowX;
    对于(int i=0;i 100)
    {
    对于(int j=0;j lowY)
    {
    lowY=等高线[i][j].y;
    lowX=等高线[i][j].x;
    }
    if(等高线[i][j].y我是新来的,所以不允许上传吗image@kashifhussain:在imageshack.us或任何其他图像共享网站(谷歌)上传图像,并在此处提供链接。@AbidRahmanK。谢谢链接是如何得到标尺的上下位置的?2条规则在image@kashifhussain请看一下我的答案,看看它是否对你有帮助。@Astor谢谢你的帮助。我试过你的代码,它工作得很好。我有两个关于代码的问题。在这里,您将匹配标尺的上下位置。当我运行代码时,low和up的结果是low(6478)和up(4464),我将如何对第二个标尺执行相同的操作(low和up),因为在输出图像中,它只为一个标尺显示粉红色。再次感谢你的帮助