我想用 ~30fps 转换许多点(最好是整个 720p 图像)。现在我只是遍历一个蒙版并寻找标记的像素。然后我将每个标记的像素转换为一个新的帧。有什么办法可以加快速度吗?该代码在 Windows 平板电脑上运行,所以我不知道 CUDA 是否可以提供帮助。
//Look for white pixels in mask image and transform them to new frame orientation
for (int row = 0; row < mask.rows; row++){
for (int col = 0; col < mask.cols; col++){
if (mask.at<uchar>(row, col) == 255){
//Point in 2D hom
p = (Mat_<double>(3, 1) << col, row, 1);
p11 = CameraMatrix480.inv()*p; //Pixel-->Camera
//Project 2D Points to table
double d = abs((p11 - midCam).dot(table_normal_cam)); //intersection of point with table surface is z value
ps = p11 - d*table_normal_cam;
p11 *= -Mat(p11 - ps).at<double>(2);
//Get point in new frame in hom camera coordinates
p11.copyTo(p_hom1(Range(0, 3), Range(0, 1)));
p_hom2 = M * p_hom1; //p_hom in frame2
//Point in frame2 in pixel coordinates
p12 = (1 / p_hom2.at<double>(2))*(CameraMatrix480*p_hom2(Range(0, 3), Range(0, 1))); //Camera-->Pixel
pixel = Point(p12.at<double>(0), p12.at<double>(1));
//Check if new location is in the frame
if (rect.contains(pixel)){
RGB& rgb = output.ptr<RGB>(pixel.y)[pixel.x];
rgb = white;
}
}
}