Ask Your Question

Revision history [back]

Camera is not opening and getting frames

include "stdafx.h"

include <stdio.h>

include <highgui.h>

include <cv.h>

include <cxcore.h>

void main(){ //Sobel edge detection for a video

CvCapture* capture = cvCreateCameraCapture(0);  //The video is loaded into a pointer of type CvCapture
IplImage* frame; IplImage*gscale_res; IplImage* edgeframe; //Declaration of structure variables to store frames
char *win = "video"; char *winEdge = "edges"; //Declaration of character pointers to store window names
cvNamedWindow(win, CV_WINDOW_AUTOSIZE); //Window is created for original image
cvNamedWindow(winEdge, CV_WINDOW_AUTOSIZE); //Window is created for resultant image

while (1)
{
    frame = cvQueryFrame(capture); //Image under consideration is captured as a shot of the video
    if (!frame)
    {
        printf("cam not found");
        break;
    }
    gscale_res = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1);//Creation of the image variable to store both the grayscale intermediate and final result
    edgeframe = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_16S, 1); //The 16-bit signed image for the result of the Sobel Edge detection
    cvCvtColor(frame, gscale_res, CV_BGR2GRAY); //Gray-scale intermediate created
    cvSobel(gscale_res, edgeframe, 1, 0, 3);// Sobel edge detection function is applied on the grayscale image and the result is put in the other variable
    cvConvertScaleAbs(edgeframe, gscale_res, 1, 0); //The 16-bit signed image is converted to an 8-bit unsigned version so it can be displayed
    cvShowImage(win, frame); //Original image is shown
    cvShowImage(winEdge, gscale_res); //Resultant image with edges detected, is shown
    char c = cvWaitKey(33); //This is to account for the frame speed of the loaded video
    cvReleaseImage(&gscale_res);
    cvReleaseImage(&edgeframe);
    if (c == 27) //If the character of code 27 or the ESCAPE character is entered, the loop will break
        break;
}

cvReleaseCapture(&capture); //Video is released from memory
cvReleaseImage(&frame);  //Images released from memory
cvDestroyWindow(win);
cvDestroyWindow(winEdge); //Windows closed

}

i have tried different arguments, cvCreateCameraCapture,cvCaptureFromCAM but still not working

click to hide/show revision 2
No.2 Revision

Camera is not opening and getting frames

include "stdafx.h"

include <stdio.h>

include <highgui.h>

include <cv.h>

include <cxcore.h>

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

void main(){ //Sobel edge detection for a video

video
CvCapture* capture = cvCreateCameraCapture(0); //The video is loaded into a pointer of type CvCapture
 IplImage* frame; IplImage*gscale_res; IplImage* edgeframe; //Declaration of structure variables to store frames
 char *win = "video"; char *winEdge = "edges"; //Declaration of character pointers to store window names
 cvNamedWindow(win, CV_WINDOW_AUTOSIZE); //Window is created for original image
 cvNamedWindow(winEdge, CV_WINDOW_AUTOSIZE); //Window is created for resultant image
 while (1)
 {
  frame = cvQueryFrame(capture); //Image under consideration is captured as a shot of the video
 if (!frame)
 {
  printf("cam not found");
 break;
 }
  gscale_res = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_8U, 1);//Creation of the image variable to store both the grayscale intermediate and final result
  edgeframe = cvCreateImage(cvSize(frame->width, frame->height), IPL_DEPTH_16S, 1); //The 16-bit signed image for the result of the Sobel Edge detection
 cvCvtColor(frame, gscale_res, CV_BGR2GRAY); //Gray-scale intermediate created
  cvSobel(gscale_res, edgeframe, 1, 0, 3);// Sobel edge detection function is applied on the grayscale image and the result is put in the other variable
  cvConvertScaleAbs(edgeframe, gscale_res, 1, 0); //The 16-bit signed image is converted to an 8-bit unsigned version so it can be displayed
 cvShowImage(win, frame); //Original image is shown
  cvShowImage(winEdge, gscale_res); //Resultant image with edges detected, is shown
 char c = cvWaitKey(33); //This is to account for the frame speed of the loaded video
 cvReleaseImage(&gscale_res);
 cvReleaseImage(&edgeframe);
  if (c == 27) //If the character of code 27 or the ESCAPE character is entered, the loop will break
 break;
 }
 cvReleaseCapture(&capture); //Video is released from memory
 cvReleaseImage(&frame); //Images released from memory
 cvDestroyWindow(win);
 cvDestroyWindow(winEdge); //Windows closed
}

}

i have tried different arguments, cvCreateCameraCapture,cvCaptureFromCAM but still not working