Ask Your Question

arifischbein's profile - activity

2016-11-23 21:11:28 -0600 asked a question webcam error

Hello. I have a porogram that takes users picture. The first photo is ok. The program open the camera, take a photo when the user presses a key, and close the window. The problem is in the next photo. The program open the camera but open the window in "background", the window is behind the console and dont detect when the user presses a key thanks!

#include <stdio.h>
#include <stdlib.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <string.h>


void camara(int);
void imprimir();

int main (void)
{
int numero;
int conf=1;

while(conf)
{
    printf("numero para el nombre de la imagen");
    scanf("%d", &numero);
    camara(numero);
    cvStartWindowThread();
    imprimir();

    printf("quiere cargar otra imagen (1 si)");
    scanf("%d", &conf);
}
}

void camara (int num)
{
    int key = 0;
    char buf[15];
sprintf(buf, "%d.jpg", num);
IplImage *frame= NULL;
CvCapture* capture;

    cvNamedWindow("imagen", CV_WINDOW_AUTOSIZE);
    capture = cvCaptureFromCAM( -1 );
    cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 31.0);


do {
    frame = cvQueryFrame( capture );
    cvShowImage("imagen", frame);
}while((key =cvWaitKey(1)) < 0);

        cvSaveImage(buf, frame,0);
        cvDestroyWindow("imagen");
        cvReleaseCapture( &capture );


}

void imprimir()
{
char p[10];
printf("pruebaaaa\n");
scanf("%s", p);
printf("%s", p);
}
2016-11-20 10:28:17 -0600 commented answer Trying to close OpenCV window has no effect

yes, sorry. the problem is with the cvDestroyWindow and cvDestroyAllWindows()

2016-11-20 10:10:55 -0600 commented answer Trying to close OpenCV window has no effect

but the problem is when i call the funtion "imprimir()", because if i try only the opencv code works

2016-11-20 09:40:10 -0600 asked a question Trying to close OpenCV window has no effect

I'm capturing the webcam image with OpenCV. That works fine. But if I want to close the OpenCV when a button is pressed, it does not work (tried both cvDestroyWindow("NameOfWindow")and cvDestroyAllWindows()). The window stays open and the application is still running. If i try only the code of opencv works correctly

thanks!

#include <stdio.h>
#include <stdlib.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <string.h>

void camera(int);
void imprimir();

int main (void)
{
int numero;
scanf("%d", &numero);
camara(numero);
imprimir();
}

void camara (int num)
{
int key = 0;
char buf[15];
sprintf(buf, "%d.jpg", num);
IplImage *frame= NULL;
CvCapture* capture;

    cvNamedWindow("imagen", CV_WINDOW_AUTOSIZE);
    capture = cvCaptureFromCAM( -1 );
    cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 31.0);


do {
    frame = cvQueryFrame( capture );
    cvShowImage("imagen", frame);
}while((key =cvWaitKey(1)) < 0);

        cvSaveImage(buf, frame,0);
        cvDestroyWindow("imagen");


}

void imprimir()
{
char p[10];
printf("pruebaaaa\n");
printf("string");
scanf("%s", p);
printf("%s", p);
}