How can I release the camera in OpenCV without closing the running program? I used the following code but camera is still in on condition.
main( int argc, char* argv[] ) 
{
    int j;
    CvCapture* capture = NULL;
    capture = cvCreateCameraCapture( 0 );
    IplImage *frames = cvQueryFrame(capture);
    //Create a new window
    cvNamedWindow( "Recording ...press ESC to stop !", CV_WINDOW_AUTOSIZE );
    while(1)
    {
        if (j<10)
        {
            frames = cvQueryFrame( capture );
            cvShowImage( "Recording ...press ESC to stop !", frames );
        }
        j++;
        if(j==10)
        cvReleaseCapture ( &capture );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }
    cvDestroyWindow ( "Recording ...press ESC to stop !");
    return 0;
}
 
     
    