Skip to content

YlmzCmlttn

Cemalettin Yılmaz Blog

Menu
  • Home
  • About Me
  • Projects
    • Iot-AR
    • Magnifi-AR
    • Smarthome-IOS
    • Others
  • Categories
    • Articles
    • Augmented Reality
    • Capture The Flag
      • Google CTF
        • 2018
    • Embedded Systems
    • IoT
    • Logisim
    • My Essays
    • Nvidia Jetson
      • Jetson TX1
    • Operating Systems
      • Kali
      • Raspbian
      • Ubuntu
    • Personal
    • Programming
      • Arduino
      • C
      • C#
      • Css
      • Html
      • Js
      • Matlab
      • Node.js
      • Python
      • Swift
      • VHDL
    • Projects
      • Embedded Systems
      • Electric
      • IoT
      • IoT-AR
      • Logisim
      • Magnifi-AR
      • Pose Estimation
    • Raspberry Pi
    • Xilinx
    • Others
Menu

Introduction OpenCV | Learning OpenCV3 C++

Posted on March 17, 2019March 17, 2019 by Yılmaz Cemalettin

This post series is the Solutions of the Learning OpenCV 3 written by Adrian Kaehler & Gary Bradski

Chapter 2: Introduction OpenCV

For this chapter, I prepare Cmake file to build the example code

 

Shell
1
2
3
4
5
6
7
8
cmake_minimum_required(VERSION 2.8)
project( Chapter2 )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( Ex3 Ex3.cpp )
target_link_libraries( Ex3 ${OpenCV_LIBS} )
add_executable( Ex4 Ex4.cpp )
target_link_libraries( Ex4 ${OpenCV_LIBS} )

Example 3

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdlib.h>
int main( int argc, char* argv[] ) {
cv::namedWindow( "Example3", cv::WINDOW_AUTOSIZE );
cv::namedWindow( "Log_Polar", cv::WINDOW_AUTOSIZE );
// ( Note: could capture from a camera by giving a camera id as an int.)
//
cv::VideoCapture capture(0);
double fps = capture.get( cv::CAP_PROP_FPS );
cv::Size size(
(int)capture.get( cv::CAP_PROP_FRAME_WIDTH ),
(int)capture.get( cv::CAP_PROP_FRAME_HEIGHT )
);
cv::VideoWriter writer;
writer.open( "test.avi", CV_FOURCC('M','J','P','G'), fps, size );
cv::Mat logpolar_frame, bgr_frame,img1,img2;
for(;;) {
capture >> bgr_frame;
if( bgr_frame.empty() ) break; // end if done
img1 = bgr_frame;
img2 = img1;
cv::imshow( "Example2_11", bgr_frame );
cv::logPolar(
bgr_frame, // Input color frame
logpolar_frame, // Output log-polar frame
cv::Point2f( // Centerpoint for log-polar transformation
bgr_frame.cols/2, // x
bgr_frame.rows/2 // y
),
40, // Magnitude (scale parameter)
cv::WARP_FILL_OUTLIERS // Fill outliers with 'zero'
);
cv::imshow( "Log_Polar", logpolar_frame );
cv::pyrDown( img2, img1);
writer << img2;
char c = cv::waitKey(10);
if( c == 27 ) break; // allow the user to break out
}
capture.release();
}

 

Example 4

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdlib.h>
int main( int argc, char* argv[] ) {
cv::namedWindow( "Example4", cv::WINDOW_AUTOSIZE );
cv::namedWindow( "Log_Polar", cv::WINDOW_AUTOSIZE );
// ( Note: could capture from a camera by giving a camera id as an int.)
//
cv::VideoCapture capture(0);
double fps = capture.get( cv::CAP_PROP_FPS );
cv::Size size(
(int)capture.get( cv::CAP_PROP_FRAME_WIDTH ),
(int)capture.get( cv::CAP_PROP_FRAME_HEIGHT )
);
cv::VideoWriter writer;
writer.open( "test.avi", CV_FOURCC('M','J','P','G'), fps, size );
cv::Mat logpolar_frame, bgr_frame,img1,img2;
for(;;) {
capture >> bgr_frame;
if( bgr_frame.empty() ) break; // end if done
img1 = bgr_frame;
img2 = img1;
cv::imshow( "Example4", bgr_frame );
cv::logPolar(
bgr_frame, // Input color frame
logpolar_frame, // Output log-polar frame
cv::Point2f( // Centerpoint for log-polar transformation
bgr_frame.cols/2, // x
bgr_frame.rows/2 // y
),
40, // Magnitude (scale parameter)
cv::WARP_FILL_OUTLIERS // Fill outliers with 'zero'
);
cv::imshow( "Log_Polar", logpolar_frame );
cv::pyrDown( img2, img1);
writer << img2;
char c = cv::waitKey(0);
cv::destroyWindow("Example4");
cv::destroyWindow("Log_Polar");
if( c == 27 ) break; // allow the user to break out
}
capture.release();
}

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

My Motto

“Learn to share, Share to learn”

LinkedIn Badge

Cemalettin Yılmaz

Ads

Archives

Categories

  • Articles (1)
  • Augmented Reality (3)
  • Capture The Flag (23)
    • Google CTF (22)
      • 2018 (13)
      • 2019 (9)
    • PicoCTF (1)
      • 2019 (1)
  • Embedded Systems (3)
  • IoT (3)
  • Logisim (1)
  • My Essays (3)
  • Nvidia Jetson (5)
    • Xavier (5)
  • Operating Systems (24)
    • Kali (3)
    • Raspbian (2)
    • Ubuntu (21)
  • Others (1)
  • Personal (1)
  • Programming (44)
    • Arduino (4)
    • C (10)
    • C# (4)
    • C++ (5)
    • Css (1)
    • CUDA (6)
    • Html (1)
    • Js (2)
    • Libraries (5)
      • OpenCV (3)
      • OpenGL (2)
    • Matlab (14)
    • Node.js (5)
    • Python (6)
    • Swift (3)
  • Programs (4)
    • Tools (4)
  • Projects (21)
    • Books Solutions (8)
    • Electric (2)
    • Embedded Systems (2)
    • Energy Harvesting (1)
    • IoT (2)
    • IoT-AR (1)
    • Logisim (1)
    • Magnifi-AR (3)
    • Pose Estimation (3)
    • Smarthome-Ios (1)
  • Raspberry Pi (3)
  • Uncategorized (2)
  • YZlib (1)

Recent Posts

  • atof stof stod problems with local floating point separator in C/C++
  • Pico CTF 2019 Answers
  • YZlib: Personal C++ Library
  • Drive to target | Google CTF 2019
  • FriendSpaceBookPlusAllAccessRedPremium | Google CTF 2019

Recent Comments

  • AbaShelha on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Peter on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on 16-Bit CPU on Logisim
  • Jenny on 16-Bit CPU on Logisim
  • MOON on 16-Bit CPU on Logisim
  • anti on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • hunkerjr on STOP GAN | Google CTF 2019
  • Shaq on 16-Bit CPU on Logisim
  • NURUL AFIQAH MOHD HASBULLAH on 16-Bit CPU on Logisim

Linkedln

© 2022 YlmzCmlttn | Powered by Superbs Personal Blog theme