Ask Your Question

razvan's profile - activity

2020-03-19 11:52:43 -0500 received badge  Notable Question (source)
2019-04-26 17:35:48 -0500 received badge  Popular Question (source)
2018-07-19 00:53:19 -0500 received badge  Notable Question (source)
2018-05-02 12:40:30 -0500 received badge  Famous Question (source)
2017-10-10 08:42:10 -0500 received badge  Notable Question (source)
2017-07-13 10:20:07 -0500 received badge  Notable Question (source)
2017-06-20 23:49:33 -0500 received badge  Popular Question (source)
2017-03-28 04:43:21 -0500 received badge  Popular Question (source)
2016-06-11 07:27:15 -0500 received badge  Famous Question (source)
2016-06-04 10:23:58 -0500 marked best answer Convert 3D point to 2D image point

Hi, using OpenCV what is the fastest/easiest way to convert 3D points to 2D image points. I know that the points are expressed in x, y and z coords in milimeters, I have the camera parameters, the height of the camera (relative to the ground plane) is expressed also in milimeters. I need an easy way to convert these 3d points (x,y,z expressed in mm) to 2d points (expressed in pixels) using the data I have and obtain the Xi, Yi coords where the origin of the coordinate system in the top left corner of the image.

Best regards!

2016-04-08 05:11:57 -0500 commented answer Can't find the button create by cvCreateButton

I would also like to display the panel automatically..

2016-04-08 05:11:05 -0500 commented question display properties window automatically

I need the same functionality, did you ever figure it out?

2016-03-29 22:35:39 -0500 received badge  Popular Question (source)
2016-03-23 01:44:31 -0500 asked a question Android Studio: OpenCV + NDK

Does anyone have a good tutorial on how to use OpenCV in C++ (NDK) with the latest Android Studio?

2016-01-09 07:41:34 -0500 received badge  Notable Question (source)
2015-11-09 00:48:15 -0500 answered a question can Opencv for android support GPU acceleration ?

GPU acceleration is supported by using CUDA instructions on (mostly) nvidia hardware. If you want additional cpu + gpu acceleration you can use renderscript in your app. Read more about it here:

I have used renderscript for color format conversions like YUV > RGB and it's really fast! Cheers!

2015-11-08 08:18:02 -0500 answered a question Android + OpenCV + Face detection + Custom Layout

Try to use a RelativeLayout or FrameLayout, the LinearLayout doesn't support Z-index, meaning that you can't draw items on top of each other. In relative or frame layouts, the views are displayed on screen in the order you add them in the xml.

Similar question was asked here:

2015-11-08 08:13:52 -0500 answered a question Build OpenCV + FastCV static linking

Solved by changing the shared libs in as follows:

LOCAL_SHARED_LIBRARIES += lopencv_java liblog libGLESv2
2015-11-05 10:23:16 -0500 commented question Build OpenCV + FastCV static linking

I also tried this:


include /Users/Razvan/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/

But no luck.. because I get undefined reference errors in the c++ files of the opencv library. ex:

/Users/Razvan/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:1804: error: undefined reference to 'cv::MatConstIterator::seek(int, bool)'
/Users/Razvan/Android/workspace/DriveAssist2Andra/DriveAssist_original/jni/GridTracking.cpp:1522: error: undefined reference to 'cv::operator*(cv::Mat const&, cv::Mat const&)'
/Users/Razvan/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/include/opencv2/core/mat.hpp:1804: error: undefined reference to 'cv::MatConstIterator::see
2015-11-05 10:22:29 -0500 asked a question Build OpenCV + FastCV static linking

Hi, I am having issues when building OpenCV and FastCV as static libs. Here is my

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

include /Users/Razvan/Android/OpenCV-2.4.10-android-sdk/sdk/native/jni/



USE_OPENGL_ES_1_1 := false

ifeq ($(USE_OPENGL_ES_1_1), true)







LOCAL_MODULE    := drive_assist

LOCAL_SRC_FILES += jni_part.cpp GridTracking.cpp CameraRendererRGB565GL2.cpp FastCVSampleRenderer.cpp CameraUtil.cpp

LOCAL_LDLIBS +=  -llog -ldl $(OPENGLES_LIB) -lfastcv 

LOCAL_CFLAGS += -Wno-write-strings $(OPENGLES_DEF) -ffast-math -O3 -fopenmp -funroll-loops

LOCAL_LDFLAGS +=-O3 -fopenmp 

LOCAL_CPPFLAGS := -O3 -flto -ffunction-sections -fdata-sections

LOCAL_CPPFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden 

LOCAL_CPPFLAGS += -fomit-frame-pointer -funroll-loops -ffast-math

LOCAL_CPPFLAGS += -mfloat-abi=softfp -DFPM_ARM -DNDEBUG




When I open the app I get this error:

11-05 15:23:12.500: D/OpenCV/StaticHelper(3391): Trying to load library opencv_java

11-05 15:23:12.500: D/OpenCV/StaticHelper(3391): Cannot load library "opencv_java"

11-05 15:23:12.500: W/System.err(3391): java.lang.UnsatisfiedLinkError: Couldn't load opencv_java from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/net.mobileway.driveassist2-2.apk"],nativeLibraryDirectories=[/data/app-lib/net.mobileway.driveassist2-2, /vendor/lib, /system/lib]]]: findLibrary returned null

If I remove the FastCV code, the OpenCV part works.. how can I make them both work? Thanks!

2015-11-02 08:49:50 -0500 commented question opencv manager wasn't initialized correctly on galaxy s6!

I also need help with the S6, any ideas?

2015-09-20 21:21:55 -0500 received badge  Popular Question (source)
2015-03-30 03:20:35 -0500 asked a question Declare float/double mat in java

Hi, how can I declare this:

Mat myMat(3, 3, cv::DataType<double>::type);

in Java/Android OpenCV?

2015-02-28 12:17:48 -0500 asked a question How to adjust rotation matrix by a known angle


I have calibrated a camera and the pitch angle considered was 0. I have the rotation mat & translation vector from using solvePnp and Rodrigues. Now, if I tilt the camera, the pitch angle changes.. how can I adjust the 3x3 rotation matrix to take into account the new pitch angle? Or the rotation vector.. The pitch angle is expressed in degrees or radians.

Basically I build up an ipm image using projectPoints function that takes the previously obtained matrixes: camera mat, rotation and translation vectors from the calibration. I simply want to modify the rotation mat to take into account the new pitch angle of the camera (mobile phone). I have rotated the points 'manually' before applying the projectPoints but the computation takes too much time.

Any ideas? Thanks!

2015-02-13 16:37:48 -0500 asked a question Android enable OpenMP


does anyone know how to enable OPenMP for an Android project using OpenCV native code?

Here's what my log prints out:

02-14 00:23:41.938: I/OpenCV/StaticHelper(24343):     Use OpenMP:    NO

I know that OpenMP is included in NDK (usage example here: ). I've done what it says on that page but when I use: #pragma omp for on a simple for loop that scans a vector, the app crashes with "fatal signal 11".

What am I missing here? Btw I use a modified example from the samples, it's Tutorial 2 Mixed Processing. All I want is to parallelize some of the for loops and nested for loops that I have in the jni c++ file while using OpenCV.

Any help/suggestion is appreciated!


2015-02-12 14:34:10 -0500 commented answer Convert rgb (brg) to rg chromaticity

In the end the scope is to try to make a better segmentation and remove shadows from the road surface. I wanted to explore the option of rg-chromaticity. Thank you very much for the answer, I will try it the next days!

2015-02-10 06:46:09 -0500 answered a question how use WarpPerspective in android?¿?

Here's an example:

Also, make sure you setup your project right and import opencv library. Follow this guide:

2015-02-10 06:31:23 -0500 answered a question Problem when automatically calculating the intrinsic camera values for reduced camera resolutions

Code snippet from here: credits to original author.

Camera.Parameters p = camera.getParameters();
int zoom = p.getZoomRatios().get(p.getZoom()).intValue();
Camera.Size sz = p.getPreviewSize();
double aspect = (double) sz.width / (double) sz.height;
double thetaV = Math.toRadians(p.getVerticalViewAngle());
double thetaH = 2d * Math.atan(aspect * Math.tan(thetaV / 2));
thetaV = 2d * Math.atan(100d * Math.tan(thetaV / 2d) / zoom);
thetaH = 2d * Math.atan(100d * Math.tan(thetaH / 2d) / zoom);

Btw, what formula are you using to compute the focal pixel? Is it something like this:

focal pixel = (imageWidth/2) / tan(horizontalAngleInRadians/2)


2015-02-09 09:17:48 -0500 commented answer Convert rgb (brg) to rg chromaticity

Yep, I need to normalize the new values, thanks! Any chance to adapt this to make it work as my 2nd version? Operating directly on channels?

2015-02-08 18:18:10 -0500 answered a question Convert Mat to char array (and vice-versa)

Eventually I changed the conversion to use pointers:

Convert mat to buffer:

unsigned char buffer[height * width];

uchar* p;
for (i = 0; i < height; ++i) {
    p = myMat.ptr<uchar>(i);
    for (j = 0; j < width; ++j) {
        buffer[i * width + j] = p[j];
2015-02-08 18:06:26 -0500 asked a question Convert rgb (brg) to rg chromaticity

I simply can't for the love of god do a simple damn conversion and it's been bugging me over the last weekend:

Can anyone help out with an efficient way to do this in OpenCV? I keep getting black images, here's my current attempt:

for (int i = 0; i < mRgb.cols; i++) {
        for (int j = 0; j < mRgb.rows; j++) {

            Vec3b intensity =<Vec3b>(j, i);
            float b = intensity.val[0];
            float g = intensity.val[1];
            float r = intensity.val[2]; 

            float rgbSum = (float) (r + g + b);
            float redNorm = (float) (r / rgbSum);
            float greenNorm = (float) (g / rgbSum);
            float blueNorm = (float) (b / rgbSum); 

  <Vec3b>(j, i)[0] = blueNorm;
  <Vec3b>(j, i)[1] = greenNorm;
  <Vec3b>(j, i)[2] = redNorm;

I am positive this can be done more efficiently, please help me out.

Isn't there a way in which you can split the channels, divide them to the channel sum and then add up the 3 new channels into a new image? In matlab it's done like this:

Edit, here's a second attempt using channels:

    Mat channel[3];
    split(mRgb, channel);

    double alpha = 1.0;
    double beta = 1.0;
    Mat tmpSum;
    Mat rgbSum;
    addWeighted(channel[0], alpha, channel[1], beta, 0.0, tmpSum);
    addWeighted(tmpSum, alpha, channel[2], beta, 0.0, rgbSum);

    Mat newR;
    Mat newG;
    Mat newB;
    divide(channel[0], rgbSum, newB);
    divide(channel[1], rgbSum, newG);
    divide(channel[2], rgbSum, newR);

    Mat in[] = { newB, newG, newR };
    int from_to[] = { 0, 0, 1, 1, 2, 2 };
    mixChannels(in, 3, &mRgb, 1, from_to, 3);

I get the famous fatal signal 11 on Android using OpenCV in ndk.


2015-01-29 10:53:13 -0500 commented answer Convert Mat to char array (and vice-versa)

I only process a small portion of the entire Mat, but I will take into account your suggestion with . Thanks for the answer, I will check the code and get back to you!

2015-01-29 06:42:51 -0500 commented answer Convert Mat to char array (and vice-versa)

I have a complex algorithm that accesses data from a byte[] (char[]) array in the way I described in my question. It will take too long to convert the entire algo.. Also, if I change data in the array, I will want to convert back to a Mat at a later phase.

2015-01-29 05:49:52 -0500 asked a question Convert Mat to char array (and vice-versa)


I tried converting a grayscale, single channel Mat (type: 8UC1) to a char[] array but somewhere it crashes. I am using android ndk and I'm coding in c++ in one of the native classes. I only get fatal signal 11 as error (probably refers to wrong memory access?).

Here's the code I am using:

unsigned char buffer[height * width];

for (int j = 0; j < height; j++) {
    for (int i = 0; i < width; i++) {
        uchar& uxy =<uchar>(j, i);
        int color = (int) uxy;
        buffer[j * width + i] = color;

I want to use a byte[] buffer to store the image (mat) and I need to access it's elements like this: y * width + x (where y=row index, x=column index). Because I don't have a byte[] structure in Android native, I decided to use a char[] array.

Is there any faster option? And I also want to convert the byte[] array (in my case, char[] array) back to a Mat. Thanks!


Converting back code (untested!):

Mat convertToMat(unsigned char *buffer) {
    Mat tmp(width, height, CV_8UC1);
    for (int x = 0; x < height; x++) {
        for (int y = 0; y < width; y++) {
            int value = (int) buffer[x * width + y];
  <int>(y, x) = value; 
    return tmp;

myMat = convertToMat(buffer);
2015-01-20 12:49:31 -0500 received badge  Enthusiast
2015-01-14 15:55:17 -0500 commented answer Obtaining coordinates of pixels lighted at specific color

As I mentioned: this is probably NOT the fastest way to solve the issue. Also, I wrote the snippet off the top of my head.. The code was not important, I wanted to give a different approach to finding his required coordinates by comparing each pixel color.