GPT答: |
7i24.cn
|
The error message is indicating that there is no `operator[]` defined for the `cv::Mat` object on line 46.
In this line, you are trying to access the second channel of the `frame` matrix using the subscript operator (`[]`). However, OpenCV's `cv::Mat` does not support direct access to individual channels using this operator.
To fix this error, you can use the `cv::split()` function to split the multi-channel image into separate single-channel images and then access each channel individually. Here's an example:
```cpp
// Splitting channels
std::vector<cv::Mat> channels;
cv::split(frame, channels);
// Accessing second channel
putText(channels[1], "Commutation success", cv::Point(200, 200), cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(0, 255, 0), 2);
```
Make sure to include `<opencv2/core.hpp>` and `<opencv2/imgproc.hpp>` headers at the top of your file for these functions and types.
Alternatively, if you only need to display text on a single-channel image (e.g., grayscale image), you can convert your multi-channel image (`frame`) into a single-channel image before accessing it:
```cpp
// Converting frame to grayscale
cv::Mat grayFrame;
cvtColor(frame, grayFrame , cv:COLOR_BGR2GRAY);
// Accessing converted grayscale frame
putText(grayFrame , "Commutation success", cv:Point(200 ,200) , FONT_HERSHEY_SIMPLEX ,1 .0,cv:Scalar(0 ,255 ,0) ,2);
```
Again make sure to include `<opencv2/core.hpp>` and `<opencv2/imgproc.hpp>` headers at the top of your file for these functions and types.
|