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.
1 | initial version |
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.
2 | No.2 Revision |
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.
3 | No.3 Revision |
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
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
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;
}
4 | No.4 Revision |
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<opencv2highgui=""
}
Video
}
5 | No.5 Revision |
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; }