Ask Your Question

Dashu's profile - activity

2019-08-07 19:29:22 -0600 received badge  Popular Question (source)
2017-03-16 04:10:29 -0600 received badge  Enthusiast
2017-03-11 10:26:18 -0600 asked a question How to find Eigenvectors of high dimension CovarianceMatrix ?

I am implementing PCA function, so I can not just call PCA function of OpenCV. I have trouble in calculating eigenvectors using Eigen function, input covariance matrix is 10000x10000 (because image size is 100x100, so 10000 features for one image, training set is only 5 images), eigenvectors returned by Eigen is not usual, every row of eigenvectors has 9999 "0" and only one "1", 00000000.....0010000....00000, I think this vector is normalised already. I try to use low dimension input covariance matrix, eigenvectors is ok. I also try to use Eigen function of Eigen library(, but it take a lot of time and I can not wait. Any function from OpenCV I can use? Or I need to implement my own Eigen function to reduce cost?

2017-01-22 04:48:10 -0600 asked a question Configure OpenCV for Android with Visual Studio(NVIDIA Nsight )

I want to develop the Android app using opencv4android SDK with Visual Studio(not C# Android), I can not use Eclipse or Android studio with some reasons.

I have installed VS 2015 professional, I set up the environment use NVIDIA Codeworks for Android version 1R4 (TADP) , it includes JDK SDK NDK ANT Gradle Eclipse CDT opencv4tegra and Nsight Tegra Visual Studio Edition, I use Eclipse to test OpenCV samples(OpenCV-\samples), all samples can compile and work, so that I assumed that the installation is ok.

image description

I create Android Application under Nsight Tegra, write a simple helloworld(pure java without native code c/c++), the program can compile and work. I import opencv module in .java file, " import org.opencv..* ;" it surely compile with error, error says that it can not find org.opencv.* , Next, I want to include opencv4android SDK(it's a challenge for me), I click Properties of project, Ant Build -> Java -> Java Source Directories, I add opencv java source dir "C:\NVPACK\OpenCV-\sdk\java\src" to it, it compile with a different error, now it can find the org.opencv folder, error is "Package R not exist", the R is org.opencv.R.

      [javac] Compiling 93 source files to C:\Users\linzi\Desktop\kk\Android1\Android1\Tegra-Android\Debug\bin\classes
      [javac] C:\NVPACK\OpenCV-\sdk\java\src\org\opencv\android\ Error: can not find symbol
      [javac] import org.opencv.R;
      [javac]                  ^
      [javac]   symbol:   class R
      [javac]   location: package org.opencv
      [javac] C:\NVPACK\OpenCV-\sdk\java\src\org\opencv\android\ error: package R not exist
      [javac]         TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
      [javac]                                                                              ^
      [javac] C:\NVPACK\OpenCV-\sdk\java\src\org\opencv\android\ error: package R not exist
      [javac]         if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
      [javac]                                     ^
      [javac] C:\NVPACK\OpenCV-\sdk\java\src\org\opencv\android\ error: package R not exist
      [javac]         mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);
      [javac]                                            ^
      [javac] 4 errors

  C:\NVPACK\android-sdk-windows\tools\ant\build.xml:716: The following error occurred while executing this line:
  C:\NVPACK\android-sdk-windows\tools\ant\build.xml:730: Compile failed; see the compiler error output for details.

  Total time: 3 seconds
  Picked up _JAVA_OPTIONS:  -Xms256m -Xmx1024m
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\Tegra-Android\Nvidia.AndroidBuild.targets(253,5): error : No errors were parsed from the Ant log. See the Output window for the build messages.
C:\NVPACK\OpenCV-\sdk\java\src\org\opencv\android\,18): warning : Error: can not find symbol
C:\NVPACK\OpenCV-\sdk\java\src\org\opencv\android\,18): warning :   symbol:   class R
C:\NVPACK\OpenCV-\sdk\java\src\org\opencv\android\,18): warning :   location: package org.opencv
C:\NVPACK\OpenCV-\sdk ...
2014-07-18 10:00:43 -0600 commented question GUI for OpenCV in Linux

@StevenPuttemans are there any tutorial for building opencv with qt?

2014-07-17 10:50:01 -0600 commented question GUI for OpenCV in Linux
2014-07-17 10:44:00 -0600 commented question GUI for OpenCV in Linux

@StevenPuttemans highgui have check-box and button? I can not find

2014-07-17 10:32:08 -0600 asked a question GUI for OpenCV in Linux

Hi friends, I am writing vision program with OpenCV in Linux, highgui of OpenCV is not suitable for me, so I made a GUI with QT, but QT take too much cpu and memory, I have to write another GUI for vision code, I need your suggestions! The picture show the GUI design, new GUI may not be beacutiful, I just want the basic function.image description Thanks!

2013-12-31 12:00:48 -0600 asked a question color tracking using OpenCV,rewrite function

Hi, friends, Happy New Year 2014! I am doing color tracking using OpenCV,I want to rewrite the follwing code, I hope it can be a looping or use function ,so less code. In fact, it's a very straight program. I need your suggestions. Thanks again!

#include <stdio.h>
#include "cv.h"
#include "highgui.h"

int main() {
    /// Variables /////////////////////////////////////////////////////////
    CvMemStorage *storage = cvCreateMemStorage(0); 
    CvSeq *contour_R, *contour_Y, *contmax_R, *contmax_Y;
    IplImage *frame, *imgHSV, *imgThresh,*imgRed, *imgYellow;
    cvNamedWindow("Original", 1);
    cvMoveWindow("Original", 750, 100);
    cvNamedWindow("Red", 1);
    cvMoveWindow("Red", 100, 100);
    cvNamedWindow("Yellow", 1);
    cvMoveWindow("Yellow", 420, 100);
    cvNamedWindow("Result", 1);
    cvMoveWindow("Result", 1080, 100);

    frame = cvLoadImage("color.jpg",1);

    if (frame == NULL) {
        printf("Image Fail\n");
        return -1;

    imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); 
    cvCvtColor(frame, imgHSV, CV_BGR2HSV);  // convert RGB to HSV

    ///////////////For Red Color////////////////////////////////////////////      
    imgRed=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1); // create binary image
    cvInRangeS(imgHSV, cvScalar(160,160,60,0), cvScalar(179,255,255,0), imgRed); // scan red color (HSV)
    cvFindContours(imgRed, storage, &contour_R, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0)); 

    int area,maxArea = 0;

    for(;contour_R != 0;contour_R = contour_R->h_next)    // find the largest red area
         area = fabs(cvContourArea(contour_R, CV_WHOLE_SEQ,1 ));
         if(area > maxArea){ 
                contmax_R = contour_R;
                maxArea = area;

    cvDrawContours(imgRed, contmax_R, CV_RGB(255,255,255), CV_RGB(255,255,255), 0, CV_FILLED, 8, cvPoint(0, 0));// draw largest red contour 
    CvRect rect_R = cvBoundingRect(contmax_R,0); 
    cvRectangle(frame, cvPoint(rect_R.x, rect_R.y), cvPoint(rect_R.x + rect_R.width, rect_R.y + rect_R.height),CV_RGB(0, 255, 0), 1, 8, 0); 
    printf("Red 1 (%d, %d)-(%d, %d)\n",rect_R.x, rect_R.y,rect_R.x + rect_R.width, rect_R.y + rect_R.height);
    /////////For Yellow Color//////////////////////////////////////////////////////////////////////////////
    imgYellow=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1); 
    cvInRangeS(imgHSV, cvScalar(22,160,60,0), cvScalar(38,255,255,0), imgYellow);
    cvFindContours(imgYellow, storage, &contour_Y, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0)); 

    maxArea = 0;

    for(;contour_Y != 0;contour_Y = contour_Y->h_next)  
        area = fabs(cvContourArea(contour_Y, CV_WHOLE_SEQ,1 ));
         if(area > maxArea){ 
                contmax_Y = contour_Y;
                maxArea = area;


    cvDrawContours(imgYellow, contmax_Y, CV_RGB(255,255,255), CV_RGB(255,255,255), 0, CV_FILLED, 8, cvPoint(0, 0)); 
    CvRect rect_Y = cvBoundingRect(contmax_Y,0);
    cvRectangle(frame, cvPoint(rect_Y.x, rect_Y.y), cvPoint(rect_Y.x + rect_Y.width, rect_Y.y + rect_Y.height),CV_RGB(0, 0, 255), 1, 8, 0); 
    printf("Yellow 1 (%d, %d)-(%d, %d)\n",rect_Y.x, rect_Y.y,rect_Y.x + rect_Y.width, rect_Y.y + rect_Y.height);
    imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
    cvAdd(imgRed,imgYellow,imgThresh,0); // 

    cvShowImage("Original", frame);
    cvShowImage("Red", imgRed);
    cvShowImage("Yellow", imgYellow);
    cvShowImage("Result", imgThresh);

    while (1) {
       int c = cvWaitKey(10);
       if((char)c==27 ) break;  



    return 0;

image description

2013-12-28 10:37:55 -0600 asked a question Track 5 different color at the same time using OpenCV

Hi, friends, I am writing vision code(C or C++) with OpenCV and cvBlob, can track N(1-5) different color at the same time. For example, the attached picture include 7 or 8 color, I want to detect 5 color (black,red,blue,green,yellow) at same time time and find the largest area of each color, track the five color area and report their position. How should I do? I need your suggestions! image description

2013-12-23 19:04:57 -0600 received badge  Critic (source)
2013-12-23 19:04:37 -0600 received badge  Scholar (source)
2013-12-23 10:39:40 -0600 asked a question Find three largest contour(achieve two now)

Hi, friends, I am coding using opencv. I want to find three largest contour in picture/video, I have write code that can find two largest contour, I have difficulty in finding third largest, so I need your suggestions,Merry Christmas! Here is my core code, how to change.

CvSeq *cont = 0
cvFindContours( tempImg, storage, &cont, sizeof(CvContour), 

CvSeq *contmax = 0;
CvSeq *contmax2 = contmax;

for(;cont;cont = cont->h_next) //get the two max area, and mark
    area = fabs(cvContourArea( cont, CV_WHOLE_SEQ )); 
    printf("area == %lf\n", area);
    if(area > maxArea)
        contmax2 = contmax;
        max2Area = maxArea;
        contmax = cont;
        maxArea = area;
    else if(area > max2Area && area < maxArea)
        contmax2 = cont;
        max2Area = area;

CvRect aRect = cvBoundingRect( contmax, 0 );
CvRect bRect = cvBoundingRect( contmax2, 0 );
2013-12-23 10:21:42 -0600 commented answer Detect color and box max color area using OpenCV

Thanks, Haris!

2013-12-20 00:32:50 -0600 commented answer Detect color and box max color area using OpenCV

Hi, Haris, how should I get (x,y) of top left corner of rectangular. Thanks

2013-12-20 00:11:21 -0600 asked a question Detect color and box max color area using OpenCV

Hi friends, I am writing colortracking code using C with OpenCV. I want to detect red color area and remove other small red area or noise, mark max red area with drawing rectangular box and printf the coordinate of the top left corner of box. This is requirement. Now I can detect red color ,but can not draw rectangular box and get the (x,y), What should I do now? Thx!

#include <stdio.h>
#include "cv.h"
#include "highgui.h"

IplImage* GetThresholdedImage(IplImage* imgHSV){        
       IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1); //Create binary image(1 channel)
       cvInRangeS(imgHSV, cvScalar(170,160,60,0), cvScalar(180,255,255,0), imgThresh); //check if array elements lie between lower and upper
       return imgThresh;

int main(){
      CvCapture* capture ;       
      capture = cvCaptureFromCAM(-1); //'-1' means default camera


            printf("Capture failure\n");
            return -1;

      IplImage* frame;


            frame = cvQueryFrame(capture);            
            if(!frame) break;

            frame=cvCloneImage(frame); // why clone? because the returned image shouldn't be released or modified
            //cvSmooth(frame, frame, CV_GAUSSIAN,3,3,0,0); //Smooth the original image using Gaussian kernel 
            cvErode(frame,frame,NULL,1);  // suture breaks,smooth image          

            IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); 
            cvCvtColor(frame, imgHSV, CV_BGR2HSV); //Change the color format from BGR to HSV
            IplImage* imgThresh = GetThresholdedImage(imgHSV);

            cvShowImage("Result", imgThresh);            
            cvShowImage("Original", frame);

            //Clean up used images          

            //Wait 10ms
            int c = cvWaitKey(10);
            //If 'ESC' is pressed, break the loop
            if((char)c==27 ) break;      

      cvDestroyAllWindows() ;

      return 0;
2013-12-19 09:07:59 -0600 asked a question C language can use cvblob?

I am writing C code (not C++) with OpenCV and cvBlob. For cvblob, always has error " /usr/local/include/cvblob.h:33:20: fatal error: iostream: No such file or directory " In my code, header has cvblob.h. here is cvblob.hlink text For OpenCV, everything is ok. so for C, how to use cvBlob?