我正在尝试将OpenCV Mat
对象中的处理数据从buffer.bits
复制到ANativeWindow_Buffer
,以便可以在显示器上看到它。
我为此收到编译错误:
void CV_Main::CameraLoop() {
bool buffer_printout = false;
while (1) {
if (m_camera_thread_stopped) { break; }
if (!m_camera_ready || !m_image_reader) { continue; }
m_image = m_image_reader->GetLatestImage();
if (m_image == nullptr) { continue; }
ANativeWindow_acquire(m_native_window);
ANativeWindow_Buffer buffer;
if (ANativeWindow_lock(m_native_window, &buffer, nullptr) < 0) {
m_image_reader->DeleteImage(m_image);
m_image = nullptr;
continue;
}
if (false == buffer_printout) {
buffer_printout = true;
LOGI("/// H-W-S-F: %d, %d, %d, %d", buffer.height, buffer.width, buffer.stride,
buffer.format);
}
display_mat = cv::Mat(buffer.height, buffer.stride, CV_8UC4, buffer.bits);
int radius = 30;
cv::Scalar color = cv::Scalar(0, 256, 256);
cv::Point point(display_mat.cols / 2, display_mat.rows / 2);
cv::circle(display_mat, point, radius, color, CV_FILLED);
std::vector<uchar> buf;
cv::imencode(".jpeg", display_mat, buf);
std::copy(buf.begin(), buf.end(), buffer.bits); // HERE IS THE COMPILATION ERROR
m_image_reader->DisplayImage(&buffer, m_image);
if (true == scan_mode) {
FaceDetect(display_mat);
}
ANativeWindow_unlockAndPost(m_native_window);
ANativeWindow_release(m_native_window);
}
FlipCamera();
}
我得到的错误是
In file included from /home/erikbylow/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/array:109:
/home/myname/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/algorithm:1811:49: error: arithmetic on a pointer to void
for (; __first != __last; ++__first, (void) ++__result)
^ ~~~~~~~~
/home/myname/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/algorithm:1837:19: note: in instantiation of function template specialization 'std::__ndk1::__copy<unsigned char *, void *>' requested here
return _VSTD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
能否实现我想要的?