aboutsummaryrefslogtreecommitdiff
path: root/modules/ocl/cv_base_class.cpp
blob: 7dbecaade46b3b79a62a25f430fedf8234984ab7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * cv_base_class.cpp - base class for all OpenCV related features
 *
 *  Copyright (c) 2016-2017 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: Andrey Parfenov <a1994ndrey@gmail.com>
 * Author: Wind Yuan <feng.yuan@intel.com>
 */

#include "cv_base_class.h"

namespace XCam {

CVBaseClass::CVBaseClass ()
{
    _cv_context = CVContext::instance ();
    XCAM_ASSERT (_cv_context.ptr ());
    _use_ocl = _cv_context->is_ocl_enabled ();
}

bool
CVBaseClass::set_ocl (bool use_ocl)
{
    if (use_ocl && !_cv_context->is_ocl_enabled ()) {
        return false;
    }
    _use_ocl = use_ocl;
    return true;
}

bool
CVBaseClass::convert_to_mat (SmartPtr<VideoBuffer> buffer, cv::Mat &image)
{

    VideoBufferInfo info = buffer->get_video_info ();
    XCAM_FAIL_RETURN (WARNING, info.format == V4L2_PIX_FMT_NV12, false, "convert_to_mat only support NV12 format");

    uint8_t *ptr = buffer->map ();
    XCAM_FAIL_RETURN (WARNING, ptr, false, "convert_to_mat buffer map failed");

    cv::Mat mat = cv::Mat (info.aligned_height * 3 / 2, info.width, CV_8UC1, ptr, info.strides[0]);
    cv::cvtColor (mat, image, cv::COLOR_YUV2BGR_NV12);
    //buffer->unmap ();

    return true;
}

bool
convert_to_mat (SmartPtr<VideoBuffer> buffer, cv::Mat &image)
{
    CVBaseClass cv_obj;
    return cv_obj.convert_to_mat (buffer, image);
}

}