Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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
Javascript opencv-图像中的线条检测(检测网格)_Javascript_Node.js_Opencv_Opencv3.0_Opencv4nodejs - Fatal编程技术网

Javascript opencv-图像中的线条检测(检测网格)

Javascript opencv-图像中的线条检测(检测网格),javascript,node.js,opencv,opencv3.0,opencv4nodejs,Javascript,Node.js,Opencv,Opencv3.0,Opencv4nodejs,我想从图像中提取网格,以便能够测量从同一台相机拍摄的其他照片上的“东西”。 每个正方形之间的距离为1米。。 我可以检测线(不是完美的),我需要帮助才能得到更干净的线,也可以得到像素的交点坐标,作为一个数组 这里是经过处理的图像 以及结果的屏幕截图 这是我的密码 const cv2=require('opencv4nodejs'); 让image1=cv2.imread('./mypicture.jpg') 设gray=image1.bgrToGray() 设dst=gray.canny(50

我想从图像中提取网格,以便能够测量从同一台相机拍摄的其他照片上的“东西”。 每个正方形之间的距离为1米。。 我可以检测线(不是完美的),我需要帮助才能得到更干净的线,也可以得到像素的交点坐标,作为一个数组

这里是经过处理的图像 以及结果的屏幕截图

这是我的密码

const cv2=require('opencv4nodejs');
让image1=cv2.imread('./mypicture.jpg')
设gray=image1.bgrToGray()
设dst=gray.canny(500800,3)
设线=dst.houghLines(2,数学PI/180.0150);
设点=[];
设isLine=(pt1,pt2,maxX=2851,maxY=10)=>{
返回Math.abs(pt1.x-pt2.x){
返回Math.abs(点x-点x)
 const cv2 = require('opencv4nodejs');
    let image1 = cv2.imread('./mypicture.jpg')
    let gray=image1.bgrToGray()
    let dst = gray.canny(500, 800,3)
    let lines= dst.houghLines(2, Math.PI/180.0, 150);
    let points = [];
    let isLine=(pt1,pt2,maxX=2851,maxY=10)=>{
        return Math.abs(pt1.x - pt2.x )<maxX || Math.abs(pt1.y - pt2.y )<maxY
    };

    let pointContain=(pt,maxX=2851,maxY=10)=>{
        return points.some((point)=>{
            return Math.abs(point.x-pt.x)<maxX && Math.abs(point.y-pt.y)<maxY
        });
    };
    for(let i in lines) {
        let rho = lines[i].x;
        let theta = lines[i].y;
        let a = Math.cos(theta)
        let b = Math.sin(theta)
        let x0=a * rho;
        let y0 =  b * rho;
        let max=1600;
        let x1=parseInt(x0 + max * (-b));
        let y1=parseInt(y0 + max * (a));
        let pt1 = new cv2.Point2(x1, y1)
        let pt2 = new cv2.Point2(parseInt(x0 - max * (-b)), parseInt(y0 - max * (a)))

        if(isLine(pt1,pt2) && !pointContain(pt1) && !pointContain(pt2)){//hack to clean lines
            points.push(pt1)
            points.push(pt2)
            console.log(pt1,pt2)
            image1.drawLine(pt1, pt2, new cv2.Vec3(0, 0, 255), 2)

        }
    }
    cv2.imshow('image1',image1)
    cv2.waitKey(0)