Android Opencv 显示在surface错乱问题
2020-11-01 本文已影响0人
luowenbin
window_buffer.bits的数据不是根据window_buffer.width而是根据window_buffer.stride来决定的,
而目标区域要绘制在window_buffer.width x window_buffer.height 区域内,因此要设置ROI。
ANativeWindow_setBuffersGeometry(window, rgba.cols, rgba.rows, WINDOW_FORMAT_RGBA_8888);
ANativeWindow_Buffer window_buffer;
if (ANativeWindow_lock(window, &window_buffer, nullptr)) {
ANativeWindow_release(window);
window = nullptr;
return;
}
long millis = currentTimeMillis();
Mat winBuffer(window_buffer.height,window_buffer.stride,CV_8UC4,window_buffer.bits);
Mat roi(winBuffer,Rect(0,0, rgba.cols, rgba.rows));
rgba.copyTo(roi);
LOGD("Cost time %d ms",(currentTimeMillis()-millis));