Ask Your Question

Revision history [back]

Problem while writing an image and video in a particular location

Image read is working properly. but while writing image in a particular location such as C or D drive. Error is 'failed to write image'. same issue for video read and write also. please help me to solve this issue.

Problem while writing an image and video in a particular location

Image read is working properly. but while writing an image in a particular location such as C or D drive. Error is 'failed to write image'. same issue for video read and write also. please help me to solve this issue.

Problem while writing an image and video in a particular location

Image read is working properly. but while writing an image in a particular location such as C or D drive. Error is 'failed to write image'. same issue for video read and write also. please help me to solve this issue.

Image write program

include<opencv2 highgui="" highgui.hpp="">

include<opencv2 core="" core.hpp="">

include<opencv2 imgproc="" imgproc.hpp="">

include <iostream>

using namespace cv; using namespace std;

int main(int argc, const char** argv) { Mat img(650, 600, CV_16UC3, Scalar(0, 50000, 50000));

if (img.empty()) 
{
    cout << "ERROR : Image cannot be loaded..!!" << endl;
    system("pause"); 
    return -1;
}


vector<int> compression_params; 

compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); 

compression_params.push_back(98); 

bool bSuccess = imwrite("C:\\Users\\sbv\\Documnents\\TestImage.jpg", img, compression_params); 

if (!bSuccess)
{

    cout << "ERROR : Failed to save the image" << endl;
    system("pause"); 

}

namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); 
imshow("MyWindow", img); 

waitKey(0);  

destroyWindow("MyWindow"); 

return 0;

}

Video write program

include<opencv2 core="" core.hpp="">

include<opencv2 highgui="" highgui.hpp="">

include<opencv2 imgproc="" imgproc.hpp="">

include <iostream>

using namespace cv; using namespace std;

int main(int argc, char* argv[]) { VideoCapture cap(0);

//VideoCapture cap("C:\\Users\\sbv\\Documents\\video.mp4");

if (!cap.isOpened())  
{
    cout << "ERROR: Cannot open the video file" << endl;
    return -1;
}

namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); 

double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); 
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); 

cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

VideoWriter VideoWriter("C:/MyVideo.avi", CV_FOURCC('P', 'I', 'M', '1'), 20, frameSize, true); 

if (!VideoWriter.isOpened()) 
{
    cout << "ERROR: Failed to write the video" << endl;
    return -1;
}

while (1)
{

    Mat frame;

    bool bSuccess = cap.read(frame); 

    if (!bSuccess) 
    {
        cout << "ERROR: Cannot read a frame from video file" << endl;
        break;
    }

    VideoWriter.write(frame); 

    imshow("MyVideo", frame); 

    if (waitKey(10) == 27) 
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}

return 0;

}

Problem while writing an image and video in a particular location

Image read is working properly. but while writing an image in a particular location such as C or D drive. Error is 'failed to write image'. same issue for video read and write also. please help me to solve this issue.

Image write program

include<opencv2
#include<opencv2 highgui="" highgui.hpp="">

include<opencv2 highgui.hpp=""> #include<opencv2 core="" core.hpp="">

include<opencv2 core.hpp=""> #include<opencv2 imgproc="" imgproc.hpp="">

include <iostream>

imgproc.hpp=""> #include <iostream> using namespace cv; using namespace std;

std; int main(int argc, const char** argv) { Mat img(650, 600, CV_16UC3, Scalar(0, 50000, 50000));

 if (img.empty()) 
{
    {
        cout << "ERROR : Image cannot be loaded..!!" << endl;
     system("pause"); 
     return -1;
}


    }


    vector<int> compression_params; 

 compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); 

 compression_params.push_back(98); 

 bool bSuccess = imwrite("C:\\Users\\sbv\\Documnents\\TestImage.jpg", img, compression_params); 

 if (!bSuccess)
{

    {

        cout << "ERROR : Failed to save the image" << endl;
     system("pause"); 

}

    }

    namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); 
 imshow("MyWindow", img); 

 waitKey(0);  

 destroyWindow("MyWindow"); 

 return 0;

}

Video } **Video write program

include<opencv2 program** #include<opencv2 core="" core.hpp="">

include<opencv2 core.hpp=""> #include<opencv2 highgui="" highgui.hpp="">

include<opencv2 highgui.hpp=""> #include<opencv2 imgproc="" imgproc.hpp="">

include <iostream>

imgproc.hpp=""> #include <iostream> using namespace cv; using namespace std;

std; int main(int argc, char* argv[]) { VideoCapture cap(0);

 //VideoCapture cap("C:\\Users\\sbv\\Documents\\video.mp4");

 if (!cap.isOpened())  
{
    {
        cout << "ERROR: Cannot open the video file" << endl;
     return -1;
}

    }

    namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); 

 double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); 
 double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); 

 cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

 Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

 VideoWriter VideoWriter("C:/MyVideo.avi", CV_FOURCC('P', 'I', 'M', '1'), 20, frameSize, true); 

 if (!VideoWriter.isOpened()) 
{
    {
        cout << "ERROR: Failed to write the video" << endl;
     return -1;
}

    }

    while (1)
{

    {

        Mat frame;

     bool bSuccess = cap.read(frame); 

     if (!bSuccess) 
    {
    {
            cout << "ERROR: Cannot read a frame from video file" << endl;
         break;
    }

    }

        VideoWriter.write(frame); 

     imshow("MyVideo", frame); 

     if (waitKey(10) == 27) 
    {
    {
            cout << "esc key is pressed by user" << endl;
         break;
    }
}

    }
    }

    return 0;

}

}

Problem while writing an image and video in a particular location

Image read is working properly. but while writing an image in a particular location such as C or D drive. Error is 'failed to write image'. same issue for video read and write also. please help me to solve this issue.

Image write program

#include<opencv2 highgui="" highgui.hpp="">
#include<opencv2 core="" core.hpp="">
#include<opencv2 imgproc="" imgproc.hpp="">
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, const char** argv)
{
    Mat img(650, 600, CV_16UC3, Scalar(0, 50000, 50000)); 

    if (img.empty()) 
    {
        cout << "ERROR : Image cannot be loaded..!!" << endl;
        system("pause"); 
        return -1;
    }


    vector<int> compression_params; 

    compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); 

    compression_params.push_back(98); 

    bool bSuccess = imwrite("C:\\Users\\sbv\\Documnents\\TestImage.jpg", img, compression_params); 

    if (!bSuccess)
    {

        cout << "ERROR : Failed to save the image" << endl;
        system("pause"); 

    }

    namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); 
    imshow("MyWindow", img); 

    waitKey(0);  

    destroyWindow("MyWindow"); 

    return 0;
}


**Video write program**
#include<opencv2 core="" core.hpp="">
#include<opencv2 highgui="" highgui.hpp="">
#include<opencv2 imgproc="" imgproc.hpp="">
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap(0); 

    //VideoCapture cap("C:\\Users\\sbv\\Documents\\video.mp4");

    if (!cap.isOpened())  
    {
        cout << "ERROR: Cannot open the video file" << endl;
        return -1;
    }

    namedWindow("MyVideo", CV_WINDOW_AUTOSIZE); 

    double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); 
    double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); 

    cout << "Frame Size = " << dWidth << "x" << dHeight << endl;

    Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));

    VideoWriter VideoWriter("C:/MyVideo.avi", CV_FOURCC('P', 'I', 'M', '1'), 20, frameSize, true); 

    if (!VideoWriter.isOpened()) 
    {
        cout << "ERROR: Failed to write the video" << endl;
        return -1;
    }

    while (1)
    {

        Mat frame;

        bool bSuccess = cap.read(frame); 

        if (!bSuccess) 
        {
            cout << "ERROR: Cannot read a frame from video file" << endl;
            break;
        }

        VideoWriter.write(frame); 

        imshow("MyVideo", frame); 

        if (waitKey(10) == 27) 
        {
            cout << "esc key is pressed by user" << endl;
            break;
        }
    }

    return 0;

}