VideoWriter not working on Win7-64Bit VM - c++

I coded the below which tries to hold a picture and count number hundred and finally grab all them to a video with following codec MP42(MPEG4-V2)
#include <stdAfx.h>
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int n=0;
char a;
int main(int, char** argv)
{
Mat image= imread("C:\\Users\\Metin\\Desktop\\images.jpg");
Mat newimage;
VideoWriter vide ("Hopdedik.avi",CV_FOURCC('M','P','4','2'),30.0,image.size());
vide.open("Hopdedik.avi",CV_FOURCC('M','P','4','2'),30.0,image.size());
for(int n=0; n<100;n++){
cout<<n<<'\n';
std::string s= to_string(static_cast<long long>(n));
image.copyTo(newimage);
putText(newimage,s,Point(100,40),cv::FONT_HERSHEY_COMPLEX,2,cv::COLORMAP_COOL,2,2,false);
imshow("asd",newimage);
if(!vide.isOpened())cout<<"can not opened";
vide.write(newimage);
waitKey(10);
}
vide.release();
return 0;
}
I started debugging on Release mode and copied the .exe files to Virtualbox Win7-64 bit. Right after I put necessary .dll files exe works but the code can't properly create the video.
I have tried to install following two codecs:
http://www.fourcc.org/downloads/angel-potion-mpeg-4--8/
and Indeo which is: http://www.afreecodec.com/codec-by-code/iv45-160.html
But it did not work.

Once I faced a similar problem where opencv couldn't read a video. There was no warning at all. The reason was that an automated string maker resulted in "opencv_mmpeg.dll" which was missing from the system. So, I debugged up to cap_ffmpeg.cpp and found this:
#if defined WIN32 || defined _WIN32
const char* module_name = "opencv_ffmpeg"
CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
#if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__)
"_64"
#endif
".dll";
So, copy opencv_ffmpeg_64.dll to your folder and you might have some results. Else, you need to debug deeply. Start by inserting into your project the file opencv/modules/highgui/src/cap.cpp (and the headers needed to be compiled) so you can debug line by line. I suppose many other files will be needed to go further down into the code.

Related

Why won't header file change the contents?

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream archivo("saludos.txt",ios::in|ios::out); // Abrir y Leer
char caract;
int cont=0;
while (!archivo.eof())
{
archivo.seekg(cont,ios::beg);
caract=archivo.get();
if (caract=='A')
{
archivo.seekp(cont,ios::beg);
archivo<< 'O';
}
cont++;
}
archivo.close ();
}
i'm using this code but when i build and run it, nothing happens in the file saludos.txt There isn't even a response on the console application. anybody know why? i'm using codeblocks and i also have #include fstream
I tried your code in my environment and it works just fine, it replace all 'A' characters with '0'.
I think your problem is with Codeblocks, if you create a new project and want to use file with the relative path in your project, you have to go to Project -> Properties -> Build targets and change the "Executing Working Dir" to your project's folder.
Or you cant try with a absolute file name with full system path first.

How do I make a portable program with OpenCV2 on C++?

I have installed OpenCV on Windows 10 and using C++ in Visual Studio.
Now I'm trying to make a program that makes several photos then saves them.
Problem:
I made a copy of project on USB flash (go to another PC) and when I try to start it from .exe file, I get this error:
How can start it without installing 1Gb of FULL OpenCV libraries?
I tried to start from release version.
My C++ source:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
#include <windows.h> // For Sleep
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap(0);
// Get the frame
Mat save_img; cap >> save_img;
if (save_img.empty())
{
std::cerr << "Something is wrong with the webcam, could not get frame." << std::endl;
}
// Save the frame into a file
imwrite("test.jpg", save_img); // A JPG FILE IS BEING SAVED
return 0;
}
My settings:
P.S. I want to make light program for making photo on Windows. And how to make real portable programs.

OpenCV imread could not open or find image

I'm doing a project with OpenCV. I am trying to run a simple code:
#include<opencv2/core.hpp>
#include<opencv2/videoio.hpp>
#include<opencv2/highgui.hpp>
#include<opencv2/imgproc.hpp>
#include<opencv2/opencv.hpp>
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv) {
cv::Mat img2 = cv::imread("test.jpg", 1);
if (!img2.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
cv::waitKey(5000);
return -1;
}
else {
cout << "Working" << endl;
cv::waitKey(5000);
}
return 0;
}
My project is a lot more bigger then this, however something simple like this isn't working for me. I have tried many things such as full path names // and \\, even tried an IplImage and convert it into Mat still no luck.
I have tried many different file types as well. If it helps I have coded it to stop the application after hitting any button, that does not work as it isn't taking any input from my keyboard.
How can I determine what is wrong?
I had this exact issue including the part about it only working in release mode. I found out I was using the release libraries for both release and debug. Because I had followed the tutorial on the OpenCV website for visual studio (incorrectly albeit), I changed the .lib folder to the correct d.lib and that fixed it.

Visual Studio 2015 OpenCV Assertion failed (size.width>0 && size.height>0) in cv::imshow windows.cpp

I've been learning a bit of c++ lately and i keep getting the same error for some reason.
Apparently, imshow isn't able to find the file.
My codes are
#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include<iostream>
#include <conio.h>
using namespace std;
using namespace cv;
int main()
{
cv::Mat img;
img = imread("1.png");
if (img.empty())
{
cout << "can't find da file\n\n" ;
}
cv::namedWindow("test");
cv::imshow("test",img);
waitKey(0);
}
I've tried putting it in the project folder along with the ".exe",
I tried listing the whole directory of the image using "/" and "\"
I've also tried not using any extensions in the code but to no avail.
Error Signs
Thanks for helping you guys :)
I always advise the same thing for these cases. It just needs a little lateral thinking. Change your code to this
int main()
{
ofstream test("test.txt");
test << "I'm here!!\n";
}
Now run this program, it will create a file called test.txt. Find out where that file is on your system and that's where you should put your 1.png file. Then you can go back to your original program confident that the file is in the right place and any remaining issues are a different problem.

lodepng, stb_image. Nothing works in my system for image loading in C++

I'm trying to load pngs or bmps into my programs. But none of the libraries I found around the web works. I have no idea why but I always get "incorrect PNG signature, it's no PNG or corrupted" for EVERY png when using lodepng. "unknown pixel format" for EVERY bmp when using SDL_loadBMP. "unknown image type" for every png when using stb_image.
I can't load anything. Maybe there is something wrong with my system ? I'm using OSX Yosemite. Here is the code.
#include <iostream>
#include <string>
#define STB_IMAGE_IMPLEMENTATION
#include <lodepng.h>
#include <stb_image.h>
using namespace std;
int main (){
string name = "res/img_test.png";
const char * cstr = name.c_str();
//lodepng
unsigned char *buffer;
unsigned int w,h;
int result = lodepng_decode32_file(&buffer, &w, &h, cstr);
cout << lodepng_error_text(result) << endl;
//stb_image
int x, y, comp;
FILE *f = fopen(cstr, "rb");
unsigned char *res;
res = stbi_load_from_file(f,&x,&y,&comp,0);
fclose(f);
cout << stbi_failure_reason() << endl;
return 0;
}
I'm using latest cmake to build this with gcc. Any recommendatation is appreciated but consider this. I've tried many files (generated by me or grabbed from internet). Tested same files with other users of the these libraries. Their code worked and mine didn't.
Edit:
Here's the source with complete cmake project >> github.com/onatbas/png_load_test.git
I solved it! Thank you everyone for trying to help.
It wasn't a code issue, afterall. It is a configuration issue. My cmake script damages the pngs and bmps when trying to copy them into destination folder. The code is fine.