Ask Your Question

jamesnzt's profile - activity

2020-05-25 04:00:08 -0600 received badge  Famous Question (source)
2019-12-11 08:41:35 -0600 received badge  Popular Question (source)
2018-11-12 10:18:12 -0600 received badge  Notable Question (source)
2018-05-05 18:31:11 -0600 received badge  Notable Question (source)
2017-05-06 06:45:49 -0600 received badge  Notable Question (source)
2017-04-24 09:13:39 -0600 received badge  Popular Question (source)
2017-02-22 06:51:08 -0600 received badge  Popular Question (source)
2017-01-21 21:25:15 -0600 received badge  Popular Question (source)
2016-04-13 23:56:05 -0600 marked best answer OpenCV and OpenGL

What is the difference between OpenCV and OpenGL? In which situation i have to go for OpenGL instead of OpenCV?

2015-03-12 05:38:22 -0600 commented question Thresholding in color image

@berak is correct. if the value of pixel is with in the range assign that value. else increment the pointer to skip that pixel.

2015-03-12 05:28:34 -0600 commented question Thresholding in color image

I got it working

cvtColor(src,img,CV_BGR2HSV);  //convering src(RGB) to img(HSV)

inRange(img,Scalar(170,155,150),Scalar(180,255,230),h1);  //creating mask using inRange.

src.copyTo(out,h1);   // copying src(RGB) image to out with mask;

This works for me Thanks @berak and

cvtColor(src,img,CV_BGR2HSV);

Mat A(src.size(),src.type(),Scalar::all(0));
for (int i=0;i<img.rows;i++)
    {
    unsigned char  *hsv=img.ptr(i);
    unsigned char *dst=A.ptr(i);
    for(int j=0;j<img.cols;j++)
        {
        unsigned char H=*hsv++;
        unsigned char S=*hsv++;
        unsigned char V=*hsv++;


 if ( (H>170 && H<=179) && (S>155 && S<255) && (V>150 && V<230) ) {
        *dst++ = H;
        *dst++ = S;
        *dst++ = V; 
    } else {
         dst++;
         dst++;
         dst++;
  }
    }
}

cvtColor(A,out,CV_HSV2BGR);

this also works thanks @LBerger

2015-03-12 03:38:27 -0600 commented question Thresholding in color image

@LBerger. Thanks for your code. but when i tried i got the following output.

image description

2015-03-12 03:01:09 -0600 commented question Thresholding in color image

@berak I got this output from using inrange() . How can i get the output of image containing the rgb image from this? Inrange produces binary image as output

image description

2015-03-12 00:36:16 -0600 asked a question Thresholding in color image

I want to threshold an color image with particular range. If the input image pixel is with in that range it must be present in the output image. i.e. my range is : R: 122-200 ; G: 80-100 ; B:40-68

if a particular pixel of image I(x,y) is with in the range eg. I(100,130) { R:130; G:94; B: 53} then the values must be copied to output image O(x,y);

Inrange function gives binary image as output; i need RGB image as output.

i tried the following.

input image -> HSV;
HSV range selection;
HSV->RGB

input matrix: img;

output matrix : A

for (int i=0;i<img.rows;i++)
{
for(int j=0;j<img.cols;j++)
{
Vec3f intensity = img.at<Vec3b>(i,j);
float H=intensity.val[0];
float S=intensity.val[1];
float V=intensity.val[2];

if(  ((H>170 && H<=179) && (S>155 && S<255) && (V>150 && V<230))
{

       A.data[A.step[0]*i + A.step[1]* j + 0] = H;
           A.data[A.step[0]*i + A.step[1]* j + 1] =S;
           A.data[A.step[0]*i + A.step[1]* j + 2] = V; 
}
    }
}

the output is

image description

it works but slows down. is there any alternative?

2015-03-09 04:20:34 -0600 edited question C++ Detection of White Particles

Hi there! I am trying to do detection of particles using OpenCV: image description

So far, I have been able to threshold the image (video) based on intensity. However, currently I am trying to use kmean to detect the oval shape particles, but to no avail. I need some help with the coding for the kmeans; I have scoured through OpenCV help pages, but yet to no avail. Will greatly appreciate help! Thank you very much


// Step 1: Obtain Ultrasound image // Step 2: Convert to black and white image // Step 3: Threshold video based on B&W intensity // Step 4: Use plusstring algorithm to find centroids of clusters // e.g. K-mean plus string algorithm // Step 5: Appoint center to each cluster // Step 6: Tracking algorithm: Kalman filter // Step 7: Output: Draw circle around particle

#include "stdafx.h"
#include<opencv/cvaux.h>
#include<opencv/highgui.h>
#include<opencv/cxcore.h>
//#include "opencv/cv.h"
//#include "opencv/highgui.h"
//#include "opencv/cxcore.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include<stdio.h>
#include<stdlib.h>

#define THRESHOLDING
    using namespace cv;
    using namespace std;

    int main(int argc, char* argv[])
    {
        VideoCapture cap("C:\\BubbleCut.avi"); // open the video file for reading

        if (!cap.isOpened())  // if not success, exit program
        {
            cout << "Cannot open the video file" << endl;
            return -1;
        }



        //Step: Declare all Mat
        Mat frame;
        Mat frame_grey;
        Mat frame_thresholded; //to give binary image 0-255
        Mat frame_houghtrans; //Canny edge gives a binary image too
        Mat labels;
        Mat data, centers;

        vector<Vec3f> circles;

        //cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

        double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

        cout << "Frame per seconds : " << fps << endl;

        //namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); create a window called "MyVideo" can be omitted

        while (1)
        {
            cap >> frame; //replace lines: receive frame from cap and store into Mat object aka frame

            if (frame.empty())
            {
                cout << "End of file" << endl << endl;
                cap.release(); //not necessary
                break;
            }


            //Step _ : Convert ultrasound raw video into greyscale video 
            cvtColor(frame, frame_grey, COLOR_RGB2GRAY);
            //plusstring algorithm, blob detection or hough transform

            #ifdef THRESHOLDING
            adaptiveThreshold(frame_grey, frame_thresholded, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 45, 0);
            #endif 

            // Step 4: Use plusstring algorithm to find centroids of clusters
            //         e.g. K-mean plus string algorithm, find parameter of circle


            **//kmeans(frame_thresholded, 8, labels, TermCriteria(CV_TERMCRIT_ITER, 10, 1.0), 3, KMEANS_PP_CENTERS, centers);**

            // Step 7: Display: Videos
            imshow("Raw video", frame); //show the frame in "MyVideo" window
            imshow("Thresholded", frame_thresholded);

            if (waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
            {
                cout << "esc key is pressed by user" << endl;
                break;
            }
        }

        return 0;

    }
2015-03-02 22:52:37 -0600 asked a question Problem with opencv in Fedora 17

I am using fedora 17. When i run a simple program to display an image, it works. but some programs running in VS 2010 with opencv 2.4.9 shows error in fedora 17.

OpenCV Error: Assertion failed (k == STD_VECTOR_MAT) in release, file /builddir/build/BUILD/OpenCV-2.3.1/modules/core/src/matrix.cpp, line 1364 terminate called after throwing an instance of 'cv::Exception'
  what():  /builddir/build/BUILD/OpenCV-2.3.1/modules/core/src/matrix.cpp:1364: error: (-215) k == STD_VECTOR_MAT in function release

fedora 17 has only updates upto opencv 2.3.1. How can i manually build newer version?

2015-02-26 04:55:36 -0600 commented question Error in running the Prespective transform in Fedora

You are correct @berak searched for opencv package in rpmfind.net. I am using fedora 17 which supports upto opencv 2.3.1. only.

2015-02-25 04:18:59 -0600 commented answer Getting coordinates for perspective transform using mousecallback()

Thanks @berak . I think i have to work more with programming. Thanks again

2015-02-25 02:42:46 -0600 commented answer Passing multiple parameters with the setMouseCallback function

how to get 4 points in onMouse function?. When i tried to get x,y coordinates of all four points, the contents of pt[0] to pt[4] are all same. How can i specify my first click is for pt[0], second left click is for pt[2], ans so on.?

2015-02-25 02:38:31 -0600 commented question Error in running the Prespective transform in Fedora

I tried updating it using yum install opencv. but it says already installed and upto date.

2015-02-25 00:37:54 -0600 asked a question Error in running the Prespective transform in Fedora

When i run the following program it is working but when i run it in fedora it shows the error message

OpenCV Error: Assertion failed (k == STD_VECTOR_MAT) in getMat, file /builddir/build/BUILD/OpenCV-2.3.1/modules/core/src/matrix.cpp, line 918
terminate called after throwing an instance of 'cv::Exception'
  what():  /builddir/build/BUILD/OpenCV-2.3.1/modules/core/src/matrix.cpp:918: error: (-215) k == STD_VECTOR_MAT in function getMat

Mainly this error is thrown when the getPerspectiveTransform(P,Q); is included.

the code is

#include "opencv2/opencv.hpp"   
using namespace cv;

int main() 
{
    Mat ocv = imread("chess.png");

    vector<Point2f> P,Q;
   P.push_back(Point2f(118,128));
    Q.push_back(Point2f(10,10)); // 10 pixel border on all sides

    P.push_back(Point2f(753,19));
    Q.push_back(Point2f(210,10));

    P.push_back(Point2f(625,328));
    Q.push_back(Point2f(210,210));

    P.push_back(Point2f(18,542));
    Q.push_back(Point2f(10,210));

    Mat rot = cv::getPerspectiveTransform(P,Q);

    Mat result;
    cv::warpPerspective(ocv, result, rot, Size(220,220));

    imshow("result",result);
    waitKey();
    return 0;
}

Why this error occoured?

2015-02-24 08:56:40 -0600 commented question Getting coordinates for perspective transform using mousecallback()

@FooBar I edited the question with my program. There is somewhere logic is missing. I cant figure it out.

2015-02-24 02:50:52 -0600 commented answer Problem with perspective

@berak i posted it as a new question

2015-02-24 02:49:21 -0600 asked a question Getting coordinates for perspective transform using mousecallback()

I tried the following code for perspective transform

  #include "opencv2/opencv.hpp"  
#include<iostream>

using namespace cv;
using namespace std;

int ival(int x, int y);

void coordinate(int event, int x, int y, int flags, void* temp)
{
    int check;
     if  ( event == EVENT_LBUTTONDOWN && flags==EVENT_FLAG_CTRLKEY)
     {
         check=ival(x,y);
         if(check=0)
             return;
     }
}


vector<Point2f> P,Q;
int main() 
{
    Mat ocv = imread("E:\\Tennis.jpg");
    namedWindow("Input");
    imshow("input",ocv);
    setMouseCallback("Input", coordinate,NULL );


    Q.push_back(Point2f(10,10)); // 10 pixel border on all sides
    Q.push_back(Point2f(210,10));
    Q.push_back(Point2f(210,210));
    Q.push_back(Point2f(10,210));

    Mat rot = cv::getPerspectiveTransform(P,Q);

    Mat result;
    cv::warpPerspective(ocv, result, rot, Size(220,220));

    imshow("result",result);
    waitKey();
    return 0;
}

I tried to get the coordinates of the source object for transform with mousecallback() but i cant able to achieve it Please tell me the logic to get four co-ordinate points using mousecallback function?

2015-02-24 02:18:49 -0600 commented answer Problem with perspective

is it possible to get the values using mousecallback()? I tried but i cant achieve it. can any one exlain the logic to do that? @berak

2015-02-24 00:39:51 -0600 commented question Image Transformation OpenCV/C++

try the code in the link. It may work

2015-02-18 00:19:45 -0600 marked best answer extracting an object from various object in background

*I have to extract an object (Eg. ball) from a group of same object in an image or in a frame of a video.

What steps/ extraction algorithm can be followed? how can i define a paticular object?* image description

2015-02-17 11:52:25 -0600 commented question Training cascade classifier- need some clarification

@StevenPuttemans I tried with increased number of positive samples(i.e. i tried with 70 positive samples and 22 negative samples) I got the trained xml file. But it didn't work in the program. while again i tried training with equal number of samples(22 positive and 22 negative) now it works and false detection is reduced. Is there any ratio of positive and negative samples so that the classifier works?

2015-02-17 11:47:44 -0600 marked best answer Offline refence manual for opencv 3

I am having opencv2refman.pdf file for my reference. Is there offline reference manual available for opencv 3.0? I searched for it but i can not found it. Help me please!

2015-02-13 04:31:59 -0600 commented question Training cascade classifier- need some clarification

Thanks @StevenPuttemans I tried the traincascade.exe it works . Due to less number of training data there are more than 20 false detection in the given image. Thanks again

2015-02-13 00:10:14 -0600 asked a question Training cascade classifier- need some clarification

I followed the tutorial in the Link I new in working with cascade classifier. So i tried training with 10 positive and 6 negative images for first time ( I read that it is not enough and for robust detection we need to train minimum of 500 samples).

  1. I put the positive and negative samples in separate folders.
  2. I created two txt files with path and name of file.
  3. I created the .vec file using

    "C:\opencv\build\x86\vc10\bin\opencv_createsamples.exe -info positivenew.txt -vec samples.vec -w 50 -h 35 PAUSE"

image description

4) I verified the samples using

C:\opencv\build\x64\vc10\bin\opencv_createsamples.exe  -vec samples.vec -w 50 -h 35 PAUSE

all works well upto this stage.

5) when i train the classifier using

C:\opencv\build\x64\vc10\bin\opencv_haartraining.exe -data class -vec samples.vec -bg Negativenew.txt -npos 10 -nneg 6 -nstages 7 -nonsym -minhitrate 0.998 -maxfalsealarm 0.5 -mem 1024 -mode ALL -w 50 -h 35

the following process was done image description

The output in the class directory contains many folders with names from 0,1,2,3...6 with files "AdaBoostCARTHaarClassifier.txt " with the content like this

1
1
3
0 0 2 16 0 -1
0 0 1 8 0 2
1 8 1 8 0 2
haar_x2_y2
6.744434e-004 0 -1
1.000000e+000 -1.000000e+000 
1.000000e+000

0
-1

but no *.xml file is found in output directory. Where did i do the mistake? Please help me in this.

2015-02-11 04:07:34 -0600 commented answer Convert rgb (brg) to rg chromaticity

yes. he also wants his second attempt to work.

2015-02-11 03:46:05 -0600 commented answer Convert rgb (brg) to rg chromaticity

mr.Razvan wanted to calculate chromaticity of the given image. He tried some program and he wants to visualize the output. he got only black screen in his attempt. the problem is according to the formula the value in the matrix is between 0 and 1 in decimals. i just multiplies the r,g,b, values with 255 to visualize the chromaticity values as image.

2015-02-10 21:59:56 -0600 commented question Error when running opencv_createsamples

I am also new in training samples. I followed the the steps in the link for creating samples. This may help you....

2015-02-10 03:57:30 -0600 commented question Error when running opencv_createsamples

I think it is not only for ubuntu. I experience the same problem in windows. I made mistake in syntax of the using createsamples.exe. thats why i refered you the link.

2015-02-09 03:44:50 -0600 commented question Image Moments

i am not sure @berak I found it used in one journal as shape feature. Then i searched for OpenCV function for it. But i cant find moment function other than moments( ) and HuMoments( ).

2015-02-09 03:04:54 -0600 asked a question Image Moments

I searched for shape features i.e. Image moments in opencv documentation. I searched for zernike moments. But there is only Hu moments is available in OpenCV documentation. Is there zernike moments available in opencv?