如何使用OpenCV在Android中将原始图像转换为RGB?

时间:2018-09-28 15:49:25

标签: android image-processing kotlin opencv3.0 opencv4android

我需要对每个原始帧进行一些处理并将其显示在预览中。这是我正在使用的代码(在Kotlin中):

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="https://www.gstatic.com/charts/loader.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container-fluid portfolio-overview-container">

    <div class="col-sm-2 ">
        <div class="row ">

            <ul class="list-group">
                <li class="list-group-item list-group-item-title text-center ">
                    <label class="portfolio-details">Side Details...</label>
                </li>
                <li class="list-group-item list-group-item-title text-center ">
                    <label class="portfolio-details"></label>
                </li>
                <li class="list-group-item list-group-item-title text-center ">
                    <label class="portfolio-details"></label>
                </li>
                <li class="list-group-item list-group-item-title text-center ">
                    <label class="portfolio-details"></label>
                </li>
                <li class="list-group-item list-group-item-title text-center ">
                    <label class="portfolio-details"></label>
                </li>

            </ul>
        </div>
    </div>
    <div class="col-sm-10">
        <div class="panel with-nav-tabs panel-tab-block">
            <div class="panel-heading ">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" role="tab" class="" href="#portfolio-projects-tab">Projects</a></li>

                    <li><a data-toggle="tab" role="tab" class="" href="#portfolio-time-management-tab">Timeline Chart</a></li>
                </ul>
            </div>
            <div class="panel-body">
                <div class="tab-content">
                    <div id="portfolio-projects-tab" class="tab-pane fade in active">
                        <div class="tab-block-content ">
                            <div class="row ">
                                <div class="col-sm-12 ">
                                    <div class="spacer-sml"></div>
                                </div>
                                <div class="col-sm-12">
                                    <h1>
                                        Project tab that is loaded by default but issue is with Timeline Chart tab chart being hidden
                                    </h1>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="portfolio-time-management-tab" class="tab-pane fade">
                        <div class="row col-xs-12">
                            <div class="spacer-sml"></div>
                        </div>
                        <div class="col-xs-11">
                            <div id="portfolio-time-management-chart" style="position:relative;"></div>

                        </div>
                        <div class="row col-xs-12">
                            <div class="spacer-sml"></div>
                        </div>
                        <div class="row ">
                            <div class="spacer-sml"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

我最终得到了一个奇怪的带有很多绿色像素的rgb框架。

根据文档,原始图像(通过ImageFormat.RAW_SENSOR)是16位单通道,多位。我可能会丢失一些东西,因为仅在CV_16UC1垫中分配字节缓冲区并将其转换为RGB不起作用。另外,即使对于线性色彩空间,最终的框架似乎也太暗。我将不胜感激!

1 个答案:

答案 0 :(得分:0)

有不同的拜耳样式布局,并且不知道相机的布局,我想您错了。 Opencv通过左上角的前两种颜色对其进行引用:cv::COLOR_Bayer BG 2BGR

在opencv中,使用不同的标志来支持这些标志:

cv::COLOR_BayerRG2BGR
cv::COLOR_BayerGR2BGR
cv::COLOR_BayerGB2RGB

...等完整列表可在此处找到:https://docs.opencv.org/3.1.0/de/d25/imgproc_color_conversions.html

您可以尝试研究平台的Bayer布局,也可以尝试直到它起作用。祝你好运!