How to write MP4 with OpenCV3

When trying to write MP4 file (H264), I tired code of

And I got error saying:

This problem is solved by changing the fourcc to the ASCII number directly to cv2.VideoWriter(), i.e.

reference:

https://devtalk.nvidia.com/default/topic/1029451/jetson-tx2/-python-what-is-the-four-characters-fourcc-code-for-mp4-encoding-on-tx2/

Install Dlib on Visual Studio 2015

Step1: Download Dlib

Step2: Use cmake to generate library

  • Use cmake to build the library. Set the directories as shown in the Figure 1 below
  • Click “Generate” and set the configuration as shown in Figure 2
  • Click “Finish”
  • Go to “C:/Users/xmeng525/Dropbox/OPENCV_STUDY/dlib-19.4/build”, open the Dlib solution
  • Run the “ALL_BUILD” project to under “Release x64” and “Debug x64”
  • You will get “Debug” and “Release” folders as shown in Figure 3, containing “dlib.lib”

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 1

 

 

 

 

 

 

 

 

 

 

 

Figure 2

Figure 3

Step3: Build a new win32 console Application for testing.

  • Add “VC++ Directories”
  • Change “C/C++ / General”
  • Change “C/C++ / Preprocessor”, add “DLIB_JPEG_SUPPORT” and “DLIB_PNG_SUPPORT”
  • Change “Linker/General/Additional Library Directories” to the directory with “Dlib.lib”
  • Change “Linker/ Input”

Step4: Testing.

  • Build a testing file “face_landmark_detection_ex.cpp” as shown in the figure below.
  • Copy the following code to the main file

 

  • Run, if there is error:
    “USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives”

    • Go to C:\Users\xmeng525\Dropbox\OPENCV_STUDY\dlib-19.4\dlib\threads\threads_kernel_shared.h
    • Comment the following code:

Step5: Get results

Store array to Mat

From: http://blog.csdn.net/u010417185/article/details/53114452

 

当采用这种方法取元素值得时候,type成为一个麻烦的问题,因为一般我们生成Mat的时候,都是这样的:

 

而取元素值时不能写成”a.at(x,y)”或者”a.at<a.type()>(x,y)”。

所以这里列出OpenCV中定义的型别和C++中型别的对应关系,

 

CV_8SC1 -> char

CV_8UC1 -> unsigned char

CV_16SC1 -> short

CV_16UC1 -> unsigned short

CV_32SC1 -> int

CV_32FC1 -> float

CV_64FC1 -> double

OpenCv中的数据型别命名规则为:CV_(比特数)+(数据类型)+(Channel数),我们也可以直接根据命名规则得到相应的数据型别。

 

下面举例:

 
若不知道所属的属性,则可以通过转变数据类型进行获取值。本人一般喜欢转为double型,代码如下:

 

 

对于保存图片的Mat来说,下面给出读取Mat中数据的例子: