我目前正在尝试使用运行 Ubuntu MATE 16.04 LTS 的 Rapsberry Pi 上的 ROS 构建自主无人机。解决现在识别红圈的计算机视觉问题。由于本质上,无人机不稳定(因为有一个内部PID控制器稳定无人机)并且由于照明条件,无人机经常检测相同的圆但是以非常不稳定的方式。为了解决这个问题,对[this] [1]问题的评论表明我尝试了视频稳定。
这是我目前正在查看的错误:
OpenCV Error: Assertion failed (a_size.width == len) in gemm, file
/tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/core/src/matmul.cpp,
line 900 terminate called after throwing an instance of
'cv::Exception' what():
/tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/core/src/matmul.cpp:900:
error: (-215) a_size.width == len in function gemm
class Tracker {
cv::Mat prevGray;
vector<cv::Point2f> trackedFeatures;
void processImage(const sensor_msgs::ImageConstPtr& msg) {
// ROS declarations
cv_bridge::CvImagePtr cv_ptr;
// Function Initializations
if (freshStart == true) {
cv::Mat rightTransform = cv::Mat::eye(3,3,CV_32FC1);
}
cv::Mat gray;
cv::Mat copy_img;
vector<cv::Point2f> corners;
try {
cv_ptr = cv_bridge::toCvCopy(msg,
sensor_msgs::image_encodings::BGR8);
}
catch (cv_bridge::Exception& e) {
ROS_INFO("cv_bridge exception");
return;
}
copy_img = cv_ptr->image;
cv::cvtColor(cv_ptr->image, gray, cv::COLOR_BGR2GRAY);
if (trackedFeatures.size() < 200) {
cv::goodFeaturesToTrack(gray,corners,200,0.01,10);
for (int i = 0; i < corners.size(); ++i) {
trackedFeatures.push_back(corners[i]);
}
}
if (!prevGray.empty()) {
vector<uchar> status;
vector<float> errors;
calcOpticalFlowPyrLK(prevGray, gray, trackedFeatures, corners,
status, errors, Size(10,10));
if (countNonZero(status) < status.size() * 0.8) {
cout << "cataclysmic error\n";
rigidTransform = cv::Mat::eye(3,3,CV_32FC1);
trackedFeatures.clear();
prevGray.release();
freshStart = true;
return;
} else {
freshStart = false;
}
cv::Mat_<float> newRigidTransform = estimateRigidTransform(
trackedFeatures, corners, false);
cv::Mat_<float> nrt33 = cv::Mat_<float>::eye(3,3);
newRigidTransform.copyTo(nrt33.rowRange(0,2));
rigidTransform *= nrt33;
trackedFeatures.clear();
for (int i = 0; i < status.size(); ++i) {
if (status[i]) {
trackedFeatures.push_back(corners[i]);
}
}
}
// Debugging to see the tracked features as of now
for (int i = 0; i < trackedFeatures.size(); ++i) {
circle(cv_ptr->image, trackedFeatures[i], 3, Scalar(0,0,255),
CV_FILLED);
}
imshow(OPENCV_WINDOW, cv_ptr->image);
cv::waitKey(3);
gray.copyTo(prevGray);
}
};
现在我知道错误在于gray.copyTo(prevGray)
语句。这是因为当我发表评论时我没有收到任何错误。
class Tracker {
// The ROS declarations
...
// Internal Declarations
...
public:
bool freshStart;
Mat_<float> rigidTransform;
...
Tracker():it_(nh1_) {
image_sub_ = it_.subscribe("/ardrone/bottom/image_raw", 1,
&Tracker::processImage, this);
image_pub_ = it_.advertise("/stabImage", 1);
cv::namedWindow(OPENCV_WINDOW);
}
~Tracker() {
cv::destroyWindow(OPENCV_WINDOW);
}
void processImage(const sensor_msgs::ImageConstPtr& msg) {
...
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "video_stabilizer");
Tracker tr;
ros::spin();
return 0;
}
答案 0 :(得分:1)
这个问题似乎是个问题。你在哪里初始化rigidTransform
?
我认为不是这一行:
cv::Mat rightTransform = cv::Mat::eye(3,3,CV_32FC1);
你需要:
rigidTransform = cv::Mat::eye(3,3,CV_32FC1);
当您注释掉gray.copyTo(prevGray)
时,问题不会发生,因为如果if (!prevGray.empty())
没有运行,则没有循环。