Ask Your Question

colol's profile - activity

2017-05-25 01:06:59 -0500 received badge  Taxonomist
2014-12-04 19:42:52 -0500 received badge  Notable Question (source)
2014-03-02 11:56:10 -0500 received badge  Popular Question (source)
2013-05-25 07:27:26 -0500 asked a question Using opencv window interface

Hello, I was wondering, is it possible to connect Kinect and show its RGB camera using opencv interface window? Since this part is where the frame is obtain from the sensor,

    NUI_IMAGE_FRAME imageFrame; // structure containing all the metadata about the frame
    NUI_LOCKED_RECT LockedRect; // contains the pointer to the actual data
     if (sensor->NuiImageStreamGetNextFrame(rgbStream, 0, &imageFrame) < 0) return;
    INuiFrameTexture* texture = imageFrame.pFrameTexture;

and this is the part where the cv window is created,

 // Create a window in which the captured images will be presented
    cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
 // Show the image captured from the camera in the window and repeat
    while ( 1 ) {
 // Get one frame
 IplImage* frame = cvQueryFrame( capture );
 if ( !frame ) {
   fprintf( stderr, "ERROR: frame is null...\n" );
   getchar();
   break;
 }

I was wondering how can I combine this two, or is it even possible?

2013-05-24 22:42:28 -0500 asked a question Combining two source code, open cv

hello I already have a kinect code that displays a window using SDL, and a code for detecting colors with each frame in a webcam. I am confuse as how to combine this two together. Any suggestions given, I will be very much thankful.

Kinect code:

#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
#include <Ole2.h>

#include <SDL_opengl.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL.h>

#include <Ole2.h>
#include <Windows.h>

#include <NuiApi.h>
#include <NuiImageCamera.h>
#include <NuiSensor.h>

#define width 640
#define height 480

// OpenGL Variables
GLuint textureId;
GLubyte data[width*height*4];

// Kinect variables
HANDLE rgbStream;
HANDLE depthStream;
INuiSensor* sensor;

//initializa SDL
bool init(int argc, char* argv[]) {
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Surface* screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL);
    return screen;
}

bool initKinect() {
    // Get a working kinect sensor
    int numSensors;
    if (NuiGetSensorCount(&numSensors) < 0 || numSensors < 1) return false;
    if (NuiCreateSensorByIndex(0, &sensor) < 0) return false;

    // Initialize sensor
    sensor->NuiInitialize(NUI_INITIALIZE_FLAG_USES_DEPTH | NUI_INITIALIZE_FLAG_USES_COLOR);
    sensor->NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, // Depth camera or rgb camera?
        NUI_IMAGE_RESOLUTION_640x480,    // Image resolution
        0,      // Image stream flags, e.g. near mode
        2,      // Number of frames to buffer
        NULL,   // Event handle
        &rgbStream);

     sensor->NuiImageStreamOpen(
        NUI_IMAGE_TYPE_DEPTH,                     // Depth camera or rgb camera?
        NUI_IMAGE_RESOLUTION_640x480,             // Image resolution
        NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE,   // Image stream flags, e.g. near mode
        2,      // Number of frames to buffer
        NULL,   // Event handle
        &depthStream);

    return sensor;
}

void getKinectData(GLubyte* dest) {
        NUI_IMAGE_FRAME imageFrame; // structure containing all the metadata about the frame
        NUI_LOCKED_RECT LockedRect; // contains the pointer to the actual data
    if (sensor->NuiImageStreamGetNextFrame(rgbStream, 0, &imageFrame) < 0) return;
    INuiFrameTexture* texture = imageFrame.pFrameTexture;
    texture->LockRect(0, &LockedRect, NULL, 0);
    if (LockedRect.Pitch != 0)
    {
        const BYTE* curr = (const BYTE*) LockedRect.pBits;
        const BYTE* dataEnd = curr + (width*height)*4;

        while (curr < dataEnd) {
            *dest++ = *curr++;
        }
    }
 texture->UnlockRect(0);
    sensor->NuiImageStreamReleaseFrame(rgbStream, &imageFrame);
}



void drawKinectData() {
    glBindTexture(GL_TEXTURE_2D, textureId);
    getKinectData(data);
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)data);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex3f(0, 0, 0);
        glTexCoord2f(1.0f, 0.0f);
        glVertex3f(width, 0, 0);
        glTexCoord2f(1.0f, 1.0f);
        glVertex3f(width, height, 0.0f);
        glTexCoord2f(0.0f, 1.0f);
        glVertex3f(0, height, 0.0f);
    glEnd();
}

void execute() {
    SDL_Event ev;
    bool running = true;
    while (running) {
        while (SDL_PollEvent(&ev)) {
            if (ev.type == SDL_QUIT) running = false;
        }
        drawKinectData();
        SDL_GL_SwapBuffers();
    }
}

int main(int argc, char* argv[]) {
    if (!init(argc, argv)) return 1;
    if (!initKinect()) return 1;

    // Initialize textures
    glGenTextures(1, &textureId);
    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*) data);
    glBindTexture(GL_TEXTURE_2D, 0);

    // OpenGL setup
    glClearColor(0,0,0,0);
    glClearDepth(1.0f);
    glEnable(GL_TEXTURE_2D);

    // Camera setup
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, height, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Main loop
    execute();
    return 0;
}

......................................................................................

detect color code:

#include"math.h"
#include"conio.h"
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include"stdio.h"

int main()
{
    //Load the image
    IplImage *src=cvLoadImage("D:\\Pattern_for_Project\\1.png",1);
    IplImage *copy=cvCreateImage( cvGetSize(src), 8, 3 );

    // create two scalar variables
    CvScalar ...
(more)
2013-05-23 07:18:00 -0500 commented answer Help in using pattern recognition with open cv

it seems that I cannot download the code, do you know any pattern recognition in images?

2013-05-23 04:13:33 -0500 asked a question Help in using pattern recognition with open cv

Hello, I am required to able to detect a pattern, which is made of three round colored circle made up of green red and blue. The position of the circle will determine the name of the pattern. hence, if the video cam goes over pattern 1, which consists of only 3 red circles, it will be able to detect and display in the console pattern 1. I have complete the detect color but not yet able to detect the pattern of the color. I know I have to create a template of the pattern, but I am not sure where to start. Is there any simple examples of pattern recognition, I can try that later I may be able to modify to fit my code?

2013-05-23 02:30:32 -0500 asked a question How to open kinect video frame using Kinect sdk and open cv c++?

Hai, I was wondering if anyone knows how to display a kinect video frame using opencv c++ with sdk, I know the new kinect sdk can support c++ language, but I am unsure how to open the kinect video frame using c++ language. The reason I require c++, is because the language I am using is all c++, and a lot of examples of kinect is connected to openni, and there are also kinect sdk opencv examples, but are there any direct examples for opening kinect video? Please help. Thank you.

2013-05-23 00:56:18 -0500 asked a question Change color detection from RGB to HSV

Hello, I have create a color detection using RGB, but I would like to change it to HSV instead. This is the code:

IplImage *src=cvLoadImage("D:\\Pattern_for_Project\\1.png",1);
IplImage *copy=cvCreateImage( cvGetSize(src), 8, 3 );

// create two scalar variables
CvScalar s,c; 

//In the 2D array of the img..count till the vertical pixel reaches the height of src
for(int i=0;i<(src->height);i++)
{

//In the 2D array of the img..count till horizontal pixel reaches the width of src
for(int j=0;j<(src->width);j++)
{

//Get the RGB values of src's i,j into a scalar s
s=cvGet2D(src,i,j);



// if RGB values (in the order as in code) are satisfying threshold condition ie. RED<50 & GREEN>100 & BLUE<100
if((s.val[2]<50)&&(s.val[1]<100)&&(s.val[0]>100)) // blue

//Remember s.val[2],s.val[1],s.val[0] are RGB correspondingly
{ 

//ie. if the pixel is predominantly Green
// here you color the detection part in the image, red green or blue
c.val[2]=0;//Set R to 0
c.val[1]=0;//Set G to 255
c.val[0]=255;//Set B to 0

//Change the pixel value of copy img to pure green(G=255 R=0 B=0)
cvSet2D(copy,i,j,c); 
}

else if((s.val[2]<50)&&(s.val[1]>100)&&(s.val[0]<100)) //green

//Remember s.val[2],s.val[1],s.val[0] are RGB correspondingly
{ 

//ie. if the pixel is predominantly Green
// here you color the detection part in the image, red green or blue
c.val[2]=0;//Set R to 0
c.val[1]=255;//Set G to 255
c.val[0]=0;//Set B to 0

//Change the pixel value of copy img to pure green(G=255 R=0 B=0)
cvSet2D(copy,i,j,c); 
}

else if((s.val[2]>100)&&(s.val[1]<50)&&(s.val[0]<100)) //red

//Remember s.val[2],s.val[1],s.val[0] are RGB correspondingly
{ 

//ie. if the pixel is predominantly Green
// here you color the detection part in the image, red green or blue
c.val[2]=255;//Set R to 0
c.val[1]=0;//Set G to 255
c.val[0]=0;//Set B to 0

//Change the pixel value of copy img to pure green(G=255 R=0 B=0)
cvSet2D(copy,i,j,c); 
}


//Set all other pixels in copy to white
else 
{
c.val[2]=0; // Red
c.val[1]=0;// Green
c.val[0]=0;// Blue
 // Now set the scalar c(now white) to the pixel in i,j in copy

cvSet2D(copy,i,j,c);
}
}
}

Any idea on how to change this code from rgb to hsb? Please help me.

2013-05-22 02:08:25 -0500 received badge  Editor (source)
2013-05-22 02:06:27 -0500 asked a question How to open webcam with open cv

Hello, I have created a code, where it can detect 3 basics colors, red green and blue. and it works perfectly. But the code works on pictures/images, how can I change the image parts into video parts so that the webcam laptop can be open and detect colors? I am new at opencv please help me. Thank you.

This is my code:

#include"math.h"
#include"conio.h"
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include"stdio.h"

int main()
{
//Load the image
IplImage *src=cvLoadImage("D:\\Pattern_for_Project\\1.png",1);
IplImage *copy=cvCreateImage( cvGetSize(src), 8, 3 );

// create two scalar variables
CvScalar s,c; 

//In the 2D array of the img..count till the vertical pixel reaches the height of src
for(int i=0;i<(src->height);i++)
{

//In the 2D array of the img..count till horizontal pixel reaches the width of src
for(int j=0;j<(src->width);j++)
{

//Get the RGB values of src's i,j into a scalar s
s=cvGet2D(src,i,j);



// if RGB values (in the order as in code) are satisfying threshold condition ie. RED<50 & GREEN>100 & BLUE<100
if((s.val[2]<50)&&(s.val[1]<100)&&(s.val[0]>100)) // blue

//Remember s.val[2],s.val[1],s.val[0] are RGB correspondingly
{ 

//ie. if the pixel is predominantly Green
// here you color the detection part in the image, red green or blue
c.val[2]=0;//Set R to 0
c.val[1]=0;//Set G to 255
c.val[0]=255;//Set B to 0

//Change the pixel value of copy img to pure green(G=255 R=0 B=0)
cvSet2D(copy,i,j,c); 
}

else if((s.val[2]<50)&&(s.val[1]>100)&&(s.val[0]<100)) //green

//Remember s.val[2],s.val[1],s.val[0] are RGB correspondingly
{ 

//ie. if the pixel is predominantly Green
// here you color the detection part in the image, red green or blue
c.val[2]=0;//Set R to 0
c.val[1]=255;//Set G to 255
c.val[0]=0;//Set B to 0

//Change the pixel value of copy img to pure green(G=255 R=0 B=0)
cvSet2D(copy,i,j,c); 
}

else if((s.val[2]>100)&&(s.val[1]<50)&&(s.val[0]<100)) //red

//Remember s.val[2],s.val[1],s.val[0] are RGB correspondingly
{ 

//ie. if the pixel is predominantly Green
// here you color the detection part in the image, red green or blue
c.val[2]=255;//Set R to 0
c.val[1]=0;//Set G to 255
c.val[0]=0;//Set B to 0

//Change the pixel value of copy img to pure green(G=255 R=0 B=0)
cvSet2D(copy,i,j,c); 
}


//Set all other pixels in copy to white
else 
{
c.val[2]=0; // Red
c.val[1]=0;// Green
c.val[0]=0;// Blue
 // Now set the scalar ...
(more)