我正在从事一个关于绿色道路上的车道检测的项目。流水线涉及到这条流水线:
- 降噪 --> BGR2HSV --> HSV 滤波器 --> Canny 边缘检测 --> 裁剪到 ROI --> 霍夫线检测 --> 处理线
在实时 Raspberry Pi 相机上,整个流程大部分时间都按预期工作。但是,如果相机画面中出现蓝色,捕获会逐渐变得模糊(参见 GIF 链接),最后,执行会通过引发“浮点异常”停止。直到现在,我都无法理解其背后的原因,因为它是蓝色所特有的。我尝试的是我只是禁用了线处理算法并在 Hough 线检测器处完成了流水线。刚刚观察了管道效应。模糊不断发生,但没有引发“浮点异常”。此外,我尝试在我的 Ubuntu 18.04 中处理,但在已经录制的视频上。当我逐帧观察过程时,蓝色没有造成任何问题。
能帮我指出问题吗?我希望我能说清楚。
GDB 输出:收到信号 SIGFPE,算术异常。 __GI_raise (sig=) at ../sysdeps/unix/sysv/linux/raise.c: 没有这样的文件或目录。
附注我在 C++ 中使用 OpenCV 4.0。
原图是这样的: ] 1 .
框架中蓝色物体后的扭曲图像: ] 2
绿色的 HSV 过滤器参数:
- H[62,90], S[148,255], V[131,206]
代码片段:
while (true) {
timeCapture = (double) cv::getTickCount(); // capture the starting time
cap >> frame_orig;
if (frame_counter != 2){
frame_counter++;
}
else {
frame_counter = 0;
// check if the input video can be opened
if (frame_orig.empty()) {
std::cout << "!!! Input video could not be opened" << std::endl;
return -1;
}
avgCounter++; // increment the process counter
frameHeight = frame_orig.rows;
frameWidth = frame_orig.cols;
// denoise the frame using a Gaussian filter
img_denoise = lanedetector.deNoise(frame_orig);
// convert from BGR to HSV colorspace
cv::cvtColor(img_denoise, frame_HSV, cv::COLOR_BGR2HSV);
// apply color thresholding HSV range for green color
cv::inRange(frame_HSV, cv::Scalar(low_H, low_S, low_V),
cv::Scalar(high_H, high_S, high_V), frame_threshed);
// canny edge detection to the color thresholded image
// (50,200,3)
Canny(frame_threshed, frame_cannied, 133, 400, 5, true);
// copy cannied image
cv::cvtColor(frame_cannied, frame_houghP, cv::COLOR_GRAY2BGR);
// std::ofstream myfile;
// myfile.open("test.txt", std::ios_base::app);
frame_masked = lanedetector.cropROI(frame_cannied);
// runs the line detection
std::vector<cv::Vec4i> line;
HoughLinesP(frame_masked, lines_houghP, 1, CV_PI / 180, threshold,
(double) maxLineGap, (double) minLineLength);
if (!lines_houghP.empty()) {
// sort the found lines from smallest y to largest y coordinate
quickSort(lines_houghP, 0, lines_houghP.size());
// reverse the order largest y to smallest y coordinate
reverseVector(lines_houghP);
// Separate lines into left and right lines
left_right_lines = lanedetector.lineSeparation(lines_houghP,
frame_masked);
// Apply regression to obtain only one line for each side of the lane
lane = lanedetector.regression(left_right_lines, frame_threshed);
// Plot lane detection
flag_plot = lanedetector.plotLane(frame_orig, lane);
for (size_t i = 0; i < lines_houghP.size(); i++) {
cv::Vec4i l = lines_houghP[i];
if (red < 0)
red = 155;
if (green < 0)
green = 55;
cv::line(frame_houghP, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]),
cv::Scalar(255, green, red), 3, cv::LINE_AA);
red = red - 20;
green = green - 20;
}
}
// std::cout << "xTrainData (python) = " << std::endl << format(frame_houghP, Formatter::FMT_PYTHON) << std::endl << std::endl;
// calculate the process time
timeCapture = ((double) cv::getTickCount() - timeCapture)
/ cv::getTickFrequency() * 1000;
if (avgCounter == fps) {
std::cout
<< "The average process time for each 30 frames in milliseconds: "
<< (avgRunTime / fps) << std::endl;
avgCounter = 0;
avgRunTime = 0;
} else
avgRunTime += timeCapture;
//imshow(window_capture_name, frame_orig);
imshow(window_lane_detected, frame_houghP);
imshow(winodw_hsv_filtered, frame_threshed);
imshow(window_canny_applied, frame_cannied);
imshow(window_masked, frame_masked);
imshow(window_vision, frame_orig);
if (!writer.isOpened()) {
std::cout << "Could not open the output video file for write\n";
return -1;
}
writer.write(frame_orig);
red = 250;
green = 250;
char key = (char) cv::waitKey(30);
if (key == 'q' || key == 27) {
break;
}
std::cin.get();
}
}
最佳答案
回答我的问题,我认为问题与 Raspberry Pi 相机有关。这不是一个真正的 Pi 相机,一个克隆。当框架中有一个蓝色物体时,像素值会像@alterigel 指出的那样发生变化。经过多次测试判断是不是软件问题,我断定是相机硬件本身的问题。
关于c++ - 当画面中出现蓝色时,图像处理失败。可能是什么原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55326088/