Ask Your Question

venkat.330's profile - activity

2016-01-22 11:00:50 -0600 received badge  Student (source)
2015-02-21 11:03:07 -0600 commented question Memory leak in the sample code to capture image with Opencv with GLIB

@berak : I was really not aware of this sorry.. Just tried it as a option...

2015-02-21 10:59:09 -0600 asked a question Memory leak in the sample code to capture image with Opencv with GLIB

I am pretty new to camera sort of drivers and trying to explore the best available options in capturing a IMAGE from a webcam.

I indeed have specs like the APP needs to cross platform & use front cam to capture image.

To start this development process i used openCV to capture image. However, when multiple cameras are connected to the system.

To implement camera functionality here is the sample code i have built.

I see some memory leak in code when capturing continuous image with openCv. Unable to find the cause.

/*
 ============================================================================
 Name        : cameraLibSam.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <opencv/highgui.h>
#include <glib.h>
//#include "libuvc/libuvc.h"
#include <stdio.h>
#include <windows.h>
#include <libusb-1.0/libusb.h>
#include <conio.h>

#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>
#include <opencv/cv.h>

#define SET 1
#define GET 0


GHashTable* cameraTable;

debug_log(char *data,int level){
    printf("%s",data);
}
typedef struct
{
    char cmd;
    int width;
    int height;
    int brightness;
    int contrast;
    int saturation;
    int gain;
    int quality;
    char file[20];
    char device[20];
    char nextcmd[20];
    int delay;
}camera_dev_t;

int process_camera (camera_dev_t *settings);

int printdev(libusb_device *dev, char *devId); //prototype of the function

 //TODO static const char version[] = VERSION;
 int run = 1;
 char temp[256];

char getCameraModel(void);

static CvCapture* capture;

void freeVals(gpointer key, gpointer value,gpointer user_data)
{
    printf("Key : %s --> Value : %s\n",key,value);
    free(key);
    free(value);
}

void printKeys(gpointer key, gpointer value,gpointer user_data)
{
    printf("Key : %s --> Value : %s\n",key,value);
}
int getcameraConfigurationInfo()
{
    GKeyFile *key_file;
    GError *error;
    gint keyCount;
    gsize num_keys;
    gchar **keys;
    gchar *value;

    key_file = g_key_file_new();
    error = NULL;
    if(!g_key_file_load_from_file(key_file,"config.ini",
            G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
                                  &error))
    {
         g_debug("%s", error->message);
         return -1;
    }

        if(g_key_file_has_group(key_file,"PROVIEW"))
        {
            keys = g_key_file_get_keys(key_file,"PROVIEW",&num_keys,&error);
            printf("dd NUMKEY %d\n",num_keys);
            int len=0;
                for(keyCount = 0;keyCount < num_keys;keyCount++)
                {
                    value=g_key_file_get_string(key_file,"PROVIEW",keys[keyCount],&error);
                    if(strstr(keys[keyCount],"Priority") != NULL)
                    {
                        len = strlen(value) + 9;
                        char *charVal = (char *)malloc(len);
                        memset(charVal,0,sizeof(charVal));
                        sprintf(charVal,"PROVIEW%s", value);
                        char *charKey = (char *)malloc(strlen(keys[keyCount])+9);
                        sprintf(charKey,"PROVIEW%s", keys[keyCount]);
                        g_hash_table_insert(cameraTable, charKey, charVal);
                        //if(value !=NULL)
                            //free(value);\
                        if (value)
                        //g_strfreev(value);
                    }
                    else
                    {
                        len = strlen(keys[keyCount]) + 9; //adding groupName ref + 1 byte extra for NULL
                        char *charKey = (char *)malloc(len);
                        char *charVal = (char *)malloc(strlen(value)+1);
                        memset(charKey,0,sizeof(charKey));
                        sprintf(charKey,"PROVIEW%s", keys[keyCount]);
                        memset(charVal,0,sizeof(charVal));
                        strcpy(charVal,value);
                        //sprintf(charVal,"PROVIEW%s", keys[keyCount]);
                        g_hash_table_insert(cameraTable, charVal, charKey);
                    }
                }
            g_hash_table_foreach(cameraTable,(GHFunc)  printKeys,NULL);
            g_strfreev(keys);
        }
        else
        {
            printf("Group not found %d\n",0);
            g_key_file_free(key_file);
            return -1;
        }
    g_key_file_free(key_file);
    return 0;
}

int printdev(libusb_device *dev,char *devId) {
    int i = 0;
    struct libusb_device_descriptor desc;
    int r = libusb_get_device_descriptor(dev, &desc);
    if (r < 0) {
        printf("failed to get device descriptor\n");
        return -2;
    }
    if((int)desc.bDeviceClass== 239){
        sprintf(devId,"%04X,%04X",desc.idVendor,desc.idProduct);
        printf("Number ...
(more)
2015-02-14 23:54:46 -0600 asked a question accessing a particular connected camera by its VID : PID

hi I am pretty new opencv and currently exploring documents and samples.

With that i am trying to check for option like openign camera based on VID / PID. This option would help me in opening a specific camera the system