在OpenCVSharp里srcImage.At<Vec3b>(i, j) = new Vec3b(0, 0, 255);报错赋值左面必须是变量,属性,索引器怎么修改
时间: 2024-03-04 10:49:24 浏览: 25
在 OpenCVSharp 中,`At` 方法返回的是引用,您可以直接将 `Vec3b` 类型的对象赋值给它。具体代码如下所示:
```
srcImage.At<Vec3b>(i, j) = new Vec3b(0, 0, 255);
```
修改为:
```
srcImage.At<Vec3b>(i, j) = new Vec3b { Item0 = 0, Item1 = 0, Item2 = 255 };
```
这将会将 `srcImage` 中第 `i` 行第 `j` 列的像素值赋值为蓝色。注意,这里使用了对象初始化器来创建 `Vec3b` 类型的对象,这是 C# 中的语法。
相关问题
dstImage.at<uchar>(y, x) = srcImage.at<uchar>((int)vPts[j].y, (int)vPts[j].x);
这段代码的作用是将源图像中指定位置的像素值赋值给目标图像中指定位置的像素值。其中 `srcImage` 是源图像,`dstImage` 是目标图像,`vPts` 是一个包含源图像中像素点位置信息的向量。具体来说,`vPts[j]` 表示源图像中第 `j` 个像素点的位置,`(int)vPts[j].x` 和 `(int)vPts[j].y` 分别表示这个像素点在源图像中的横坐标和纵坐标,然后使用 `at<uchar>()` 函数可以获取该像素点的灰度值,将该值赋给目标图像中对应位置的像素值即可。这段代码应该是在图像配准或者图像融合等操作中使用的。
public static void fitLineSubPixel(Mat srcImage, List<Point2f> fitPList, ref Point2f p1, ref Point2f p2) { if (fitPList.Count < 2) return; MatOfPoint2f matFitPList = new MatOfPoint2f(); matFitPList.FromList(fitPList); // Compute the initial line estimate using cv::fitLine() Mat line = new Mat(); Cv2.FitLine(matFitPList, line, DistanceTypes.L2, 0, 0.01, 0.01); // Extract the line parameters float vx = line.At<float>(0, 0); float vy = line.At<float>(1, 0); float x0 = line.At<float>(2, 0); float y0 = line.At<float>(3, 0); // Compute the endpoints of the line segment float lefty = (-x0 * vy / vx) + y0; float righty = ((srcImage.Width - x0) * vy / vx) + y0; // Refine the endpoints to subpixel accuracy using cv::fitLine() again MatOfPoint2f subMatFitPList = new MatOfPoint2f(); subMatFitPList.FromArray(new Point2f[] { new Point2f(0, lefty), new Point2f(srcImage.Width - 1, righty) }); Cv2.FitLine(subMatFitPList, line, DistanceTypes.L2, 0, 0.01, 0.01); vx = line.At<float>(0, 0); vy = line.At<float>(1, 0); x0 = line.At<float>(2, 0); y0 = line.At<float>(3, 0); // Update the endpoints based on the refined line estimate lefty = (-x0 * vy / vx) + y0; righty = ((srcImage.Width - x0) * vy / vx) + y0; p1 = new Point2f(0, lefty); p2 = new Point2f(srcImage.Width - 1, righty); }未能找到类型或命名空间名“MatOfPoint2f”(是否缺少 using 指令或程序集引用?,请生成新程序
看起来这段代码是使用OpenCV库进行图像处理的,但是编译器报错未能找到类型或命名空间名“MatOfPoint2f”,可能是缺少了相关的using指令或者程序集引用。请确保你的项目引用了OpenCV库,并且在代码文件开头添加了using OpenCvSharp;的using指令。如果还是无法解决问题,可以尝试在项目中手动添加OpenCV库的引用。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)