Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.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++ 如何检测图像部分的高度?_C++_Image_Opencv - Fatal编程技术网

C++ 如何检测图像部分的高度?

C++ 如何检测图像部分的高度?,c++,image,opencv,C++,Image,Opencv,有时医生不把它压平。我想做的是检查它是否压平。 我用一个精明的算法来处理它 // Example 2-7. The Canny edge detector writes its output to a single-channel (grayscale) image // 2 #include <opencv2/opencv.hpp> void help(char** argv) { std::cout << "\n" <

有时医生不把它压平。我想做的是检查它是否压平。 我用一个精明的算法来处理它

// Example 2-7. The Canny edge detector writes its output to a single-channel (grayscale) image
// 2
#include <opencv2/opencv.hpp>

void help(char** argv) {
    std::cout << "\n"
        << "\nExample 2-7. The Canny edge detector writes its output to a single-channel (grayscale) image"
        << "\nCall:\n"
        << argv[0] << " <path/image>\n"
        << "For example:\n"
        << argv[0] << " ../fruits.jpg\n"
        << std::endl;
}


int main(int argc, char** argv) {

    if (argc != 2) {
        help(argv);
        return 0;
    }

    cv::Mat img_rgb, img_gry, img_cny;

    cv::namedWindow("Example Gray", cv::WINDOW_AUTOSIZE);
    cv::namedWindow("Example Canny", cv::WINDOW_AUTOSIZE);

    img_rgb = cv::imread(argv[1]);

    cv::cvtColor(img_rgb, img_gry, cv::COLOR_BGR2GRAY);
    cv::imshow("Example Gray", img_gry);

    cv::Canny(img_gry, img_cny, 10, 100, 3, true);
    cv::imshow("Example Canny", img_cny);

    cv::waitKey(0);

}

然后用等高线得到顶部? 有没有像模板匹配之类的解决方案,因为相机拍摄的照片可能略有不同。

Rect Rect(150,060300); Mat image_roi=img_rgb(rect)

cv::cvtColor(图像roi、图像灰度、cv::COLOR\bgr2灰度);
cv::imshow(“灰色示例”,img_gry);
cv::blur(img_gry,img_blr,cv::Size(3,3));
cv::imshow(“示例模糊”,img_blr);
简历::Canny(img_blr,img_cny,10100,3,真);
cv::imshow(“示例Canny”,img_cny);
矢量线;
HoughLines(img_cny,lines,1,CV_PI/180,180,0,0);

这里的阈值很难确定。

什么会“变平”?你想测量什么?变“扁平”意味着每根管子都和其他管子一样高。看图片,一根管子的位置不好。我想测量的是找出它。我想你可能想在运行
cv::Canny
,比如,
cv::Mat img\u blr;cv::blur(img_gry,img_blr,cv::Size(3,3))
从反射中移除瑕疵(然后使用
img\u blr
而不是
img\u gry
cv::Canny
)-我对OpenCV还不太了解,所以不知道从哪里开始。你知道扁平状态下管子的理想高度。若背景为固定平面白色,则扫描高于某个阈值高度的像素存在。这可以通过搜索像素来完成。但是背景宽度可以增加。所以,窗户或灯不应该出现在图片中。我已经更新了问题。
Rect rect(150, 0, 600, 300);
Mat image_roi = img_rgb(rect);
cv::cvtColor(image_roi, img_gry, cv::COLOR_BGR2GRAY);
cv::imshow("Example Gray", img_gry);

cv::blur(img_gry, img_blr, cv::Size(3, 3));
cv::imshow("Example blur", img_blr);

cv::Canny(img_blr, img_cny, 10, 100, 3, true);
cv::imshow("Example Canny", img_cny);

vector<Vec2f> lines;
HoughLines(img_cny, lines, 1, CV_PI / 180, 180, 0, 0);