#include<sstream>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <cassert>
#include <cmath>
#include <fstream>
#include <time.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/types_c.h"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/video/tracking.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/calib3d/calib3d.hpp"
using namespace std;
using namespace cv;
int main(int argc, char **argv)
{
VideoCapture cap("test2.mp4");
assert(cap.isOpened());
cap>>prev;
VideoWriter outputVideo;
if (!outputVideo.isOpened())outputVideo.open("compare.mp4" , CV_FOURCC('X','V','I','D'), 24,cvSize(cur.rows, cur.cols*2+10), true);
outputVideo<< prev;
while(true) {
stringstream ss;
string name = "cropped_";
string type = ".jpg";
ss<<name<<(chk)<<type;
string filename = ss.str();
ss.str("");
imwrite(filename, canvas);
outputVideo<< canvas;
prev = cur.clone();//cur.copyTo(prev);
prev_ref = cur_ref.clone();//cur.copyTo(prev);
cur_grey.copyTo(prev_grey);
cout << "Frame: " << k << "/" << max_frames << " - good optical flow: " << prev_corner2.size() << endl;
k++;
}
Question:It is a small description of my code.Now when I try to write my canvas(variable of type Mat in OpenCV) for creating a video.It's giving an error.Even if I try for .avi file or .mp4 file it doesn't write/create a video.Please help me out.It shows an error "[mp4 # 0xa0aac0] Tag XVID/0x44495658 incompatible with output codec id '13' error ".I am using ubuntu 14.04 with intel core processor-i5
Related
I am trying to use the Mediapipe Hand tflite file using TensorFlowLite. But whenever I am getting an error when referring to the input tensor data and dimensions.\
This is the main.cpp:
#include <iostream>
#include <cstdio>
#include <vector>
#include <tensorflow/lite/interpreter.h>
#include <tensorflow/lite/kernels/register.h>
#include <tensorflow/lite/model.h>
#include <tensorflow/lite/optional_debug_tools.h>
#include <flatbuffers/flatbuffers.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <tensorflow/lite/model_builder.h>
#include <tensorflow/lite/string_util.h>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/builtin_op_data.h"
#include "tensorflow/lite/kernels/register.h"
using namespace std;
int main()
{
const char* filename = "C:/Users/naren/OneDrive/Documents/MediapipeHands/hand_landmark_full.tflite";
const char* image_filename = "C:/Users/naren/OneDrive/Documents/MediapipeHands/hand.jpg";
std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile(filename);
if (model == nullptr) {
cerr << "Fail to build FlatBufferModel from file: " << filename << std::endl;
exit(1);
}
tflite::ops::builtin::BuiltinOpResolver resolver;
std::unique_ptr<tflite::Interpreter> interpreter;
if (tflite::InterpreterBuilder(*model, resolver) (&interpreter) != kTfLiteOk) {
std::cerr << "Failed to build interpreter." << std::endl;
exit(1);
}
interpreter->SetNumThreads(-1);
if (interpreter->AllocateTensors() != kTfLiteOk) {
cerr << "Failed to allocate tensors." << endl;
exit(1);
}
cv::Mat image;
auto frame = cv::imread(image_filename);
if (frame.empty()) {
cout << "Image not loaded";
exit(1);
}
cv::cvtColor(frame, image, cv::COLOR_BGR2RGB);
cv::flip(image, image, 1);
cv::imshow("Image", image);
cv::waitKey(10);
const std::vector<int>& inputs = interpreter->inputs();
TfLiteTensor* inputTensor = interpreter->tensor(inputs[0]);
return 0;
}
The program is failing at the last line before the return 0 line. If we run only uptil cv::waitKey(10), then a debug assertion window pops up. I also have the cmake file, please comment if you need it.
My question is how to correctly write a protobuf message in text format to a file. In the program below I create a NetParameter object which is a message
field in message field in caffe.proto.
When I call print() and PrintToString() they return failure.
I can print the mesaage on the console with printf("%s", data.c_str()); but notting is written to file?
#include <fcntl.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <stdint.h>
#include <algorithm>
#include <fstream> // NOLINT(readability/streams)
#include <string>
#include <vector>
#include <string>
#include "caffe.pb.h"
#include <iostream>
#include <caffe/caffe.hpp>
using namespace std;
using google::protobuf::Message;
using google::protobuf::io::CodedInputStream;
using google::protobuf::io::CodedOutputStream;
using google::protobuf::io::FileInputStream;
using google::protobuf::io::FileOutputStream;
using google::protobuf::io::ZeroCopyInputStream;
using google::protobuf::io::ZeroCopyOutputStream;
using google::protobuf::TextFormat;
int main()
{
caffe::NetParameter param;
const char *filename = "./test.prototxt";
int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd == -1)
cout << "File not found: " << filename;
google::protobuf::io::FileOutputStream* output = new google::protobuf::io::FileOutputStream(fd);
param.set_name("AlexNet");
param.add_input_dim(0);
param.add_input_dim(1);
param.add_input_dim(2);
param.set_input_dim(0, 3);
param.set_input_dim(1, 3);
param.set_input_dim(2, 3);
std::string data;
bool success = google::protobuf::TextFormat::PrintToString(param, &data);
std::cout << "bool is " << success << std::endl;
printf("%s", data.c_str());
bool success1 = google::protobuf::TextFormat::Print(param, output);
std::cout << "bool is " << success << std::endl;
close(fd);
return 0;
}
I'm having issue in the ifstream function, I have tried using the argv[1] as parameter but wont load the map, the map is located in the same folder of main code.
I'm stucked here and can not debug.
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
using namespace std;
int main (int argc, char *argv[]){
int h;
int w;
int var;
string inputLine;
ifstream f;
f.open("map.pgm",ios::in);
if (!f){
cout << "error" << endl;
exit(1);
}
I'm using Visual Studio 2017
Change this line:
if (!f){
by this:
if (!f.is_open()){
BTW you can check current directory path with GetModuleFileName
#include <iostream>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
using namespace std;
using namespace cv;
int main()
{
char filename[] = "IMG_0851";
Mat image; //create an image matrix
I want to analysis the image in grayscale
image = cvLoadImage(filename,CV_LOAD_IMAGE_GRAYSCALE); //load image in grayscale directly
if (image.empty())
{
cout << "Image could not be found" << endl;
return -1;
}
imshow("Image in RGB", image);
cvWaitKey(0); //wait for a keystroke in the window
return 0;
}
Build succeeded, however, the image cannot be found & program ended exit code: 255.
#include "Stdafx.h"
#include "FishTracker.h"
#include <string>
#include "Utils.h"
#include <fstream>
using namespace std;
using namespace cv;
int main()
{
std::string videopath;
videopath = "E:\\TUKLNUST\\fishdata2\\Damo\\AR2-6\\Tetraodontidae_Lagocephalus_sceleratus_AD\\00001\\";
ifstream str;
str.open((videopath + DATA_TXT).c_str());
if (str.is_open())
{
cout << "file is open.";
}
}
file is open but str is this.
+ str {_Filebuffer={_Set_eback=0xcccccccc <Error reading characters of string.> _Set_egptr=0xcccccccc <Error reading characters of string.> ...} } std::basic_ifstream<char,std::char_traits<char> >
Configs:
win32, Debug
Visual Studio 2013
#include "Stdafx.h"
#include "FishTracker.h"
#include <string>
#include "Utils.h"
#include <fstream>
using namespace std;
using namespace cv;
int main()
{
std::string videopath;
videopath = "E:\\TUKLNUST\\fishdata2\\Damo\\AR2-6\\Tetraodontidae_Lagocephalus_sceleratus_AD\\00001\\";
ifstream str;
str.open((videopath + "DATA_TXT").c_str());
if (str.is_open())
{
cout << "file is open.";
}
}