input:ABS_DISTANCE上报空指针错误


在probe函数中设置事件类型EV_ABS和支持的事件码ABS_DISTANCE:

input_set_capability(input_dev, EV_ABS, ABS_DISTANCE);
然后在工作队列里上报传感器的数据:

input_report_abs(dt->input, ABS_DISTANCE, 1);
input_sync(dt->input);

运行程序,每次到上报时候就会出现空指针错误,内核就跑飞了。

解决办法:

因为ABS_DISTANCE需要使用下面的函数设置相关的参数,如距离的最小,最大值等。才能正常上报。
添加如下内容在probe函数中。

input_set_abs_params(input_dev, ABS_DISTANCE, 0, 1, 0, 0);

函数定义如下:

void input_set_abs_params(struct input_dev *dev, unsigned int axis,
<span>			</span>  int min, int max, int fuzz, int flat)
{
<span>	</span>struct input_absinfo *absinfo;


<span>	</span>input_alloc_absinfo(dev);
<span>	</span>if (!dev->absinfo)
<span>		</span>return;


<span>	</span>absinfo = &dev->absinfo[axis];
<span>	</span>absinfo->minimum = min;
<span>	</span>absinfo->maximum = max;
<span>	</span>absinfo->fuzz = fuzz;
<span>	</span>absinfo->flat = flat;


<span>	</span>dev->absbit[BIT_WORD(axis)] |= BIT_MASK(axis);
}

这个错误通常是由于传递给 `findContours()` 函数的轮廓参数类型不正确导致的。 在你的代码中,`findContours()` 函数的第一个参数是一个 `cv::Mat` 类型的矩阵,而第二个参数 `intersectionPolygon` 是一个 `std::vector<cv::Point>` 类型的向量。这里的问题是,`findContours()` 函数期望的第二个参数是一个用于存储轮廓的输出向量,而你传递了一个点的向量。因此,你需要将 `intersectionPolygon` 声明为一个 `std::vector<std::vector<cv::Point>>` 类型的向量,以存储轮廓。 更改后的代码如下所示: ``` bool isPolygonInside(const std::vector<cv::Point>& polygon1, const std::vector<cv::Point>& polygon2, double& outsideArea) { // Check if all vertices of polygon1 are inside polygon2 bool allInside = true; for (const auto& vertex : polygon1) { double distance = cv::pointPolygonTest(polygon2, vertex, true); if (distance < 0) { allInside = false; break; } } if (allInside) { return true; } // Polygon1 is partially or completely outside polygon2 std::vector<std::vector<cv::Point>> intersectionPolygon; // 修改此处 if (cv::isContourConvex(polygon1) && cv::isContourConvex(polygon2)) { cv::Mat intersectionMat; cv::intersectConvexConvex(cv::Mat(polygon1), cv::Mat(polygon2), intersectionMat); if (cv::countNonZero(intersectionMat) > 0) { cv::findContours(intersectionMat, intersectionPolygon, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); } } else { std::vector<cv::Point> hull1, hull2; cv::convexHull(polygon1, hull1); cv::convexHull(polygon2, hull2); std::vector<cv::Point> hullIntersection; cv::convexHull(hull1, hullIntersection, false, false); cv::fillConvexPoly(cv::Mat(hullIntersection), hull2, cv::Scalar(0), false); cv::findContours(cv::Mat(hullIntersection), intersectionPolygon, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); } if (intersectionPolygon.empty()) { outsideArea = 0; return false; } double intersectionArea = std::abs(cv::contourArea(intersectionPolygon[0])); // 修改此处 double polygon1Area = std::abs(cv::contourArea(polygon1)); outsideArea = polygon1Area - intersectionArea; return true; // 修改此处 } ``` 你需要将 `intersectionPolygon` 的类型从 `std::vector<cv::Point>` 改为 `std::vector<std::vector<cv::Point>>`,以及在计算交集面积时使用 `intersectionPolygon[0]` 来获取轮廓。 另外,最后一行需要返回 true,因为在计算出多边形1在多边形2外部的面积后,函数应该返回 true。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值