1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

samples: avoid using of legacy C-like API

- CV_RGB() macro is moved into opencv2/imgproc.hpp from imgproc_c.h
- samples/cpp/filestorage_base64.cpp is dropped
This commit is contained in:
Alexander Alekhin
2018-03-26 13:02:57 +03:00
parent e06d1e8083
commit 7f9253ea0a
17 changed files with 26 additions and 101 deletions
+2 -2
View File
@@ -133,7 +133,7 @@ static double rateFrame(Mat & frame)
unsigned long int sum = 0;
unsigned long int size = frame.cols * frame.rows;
Mat edges;
cvtColor(frame, edges, CV_BGR2GRAY);
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
@@ -324,7 +324,7 @@ int main(int argc, char ** argv)
if (!GlobalArgs.output.empty())
{
Size S = Size((int) cap.get(CAP_PROP_FRAME_WIDTH), (int) cap.get(CAP_PROP_FRAME_HEIGHT));
int fourCC = CV_FOURCC('M', 'J', 'P', 'G');
int fourCC = VideoWriter::fourcc('M', 'J', 'P', 'G');
videoWriter.open(GlobalArgs.output, fourCC, GlobalArgs.fps, S, true);
if (!videoWriter.isOpened())
{
+2 -2
View File
@@ -218,8 +218,8 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade,
circle( img, center, radius, color, 3, 8, 0 );
}
else
rectangle( img, cvPoint(cvRound(r.x*scale), cvRound(r.y*scale)),
cvPoint(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
rectangle( img, Point(cvRound(r.x*scale), cvRound(r.y*scale)),
Point(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
color, 3, 8, 0);
if( nestedCascade.empty() )
continue;
-71
View File
@@ -1,71 +0,0 @@
#include "opencv2/core.hpp"
#include <iostream>
#include <string>
static CvFileStorage * three_same_ways_of_write_base64()
{
CvFileStorage * fs = 0;
cv::RNG rng;
switch ( rng.uniform( 0, 2 ) )
{
case 0:
//! [suffix_in_file_name]
fs = cvOpenFileStorage( "example.yml?base64", 0, CV_STORAGE_WRITE );
//! [suffix_in_file_name]
break;
case 1:
//! [flag_write_base64]
fs = cvOpenFileStorage( "example.yml" , 0, CV_STORAGE_WRITE_BASE64 );
//! [flag_write_base64]
break;
case 2:
//! [flag_write_and_flag_base64]
fs = cvOpenFileStorage( "example.yml" , 0, CV_STORAGE_WRITE | CV_STORAGE_BASE64 );
//! [flag_write_and_flag_base64]
break;
default:
break;
}
return fs;
}
static void two_ways_to_write_rawdata_in_base64()
{
std::vector<int> rawdata(10, 0x00010203);
{ // [1]
//! [without_base64_flag]
CvFileStorage* fs = cvOpenFileStorage( "example.xml", 0, CV_STORAGE_WRITE );
// both CV_NODE_SEQ and "binary" are necessary.
cvStartWriteStruct(fs, "rawdata", CV_NODE_SEQ | CV_NODE_FLOW, "binary");
cvWriteRawDataBase64(fs, rawdata.data(), static_cast<int>(rawdata.size()), "i");
cvEndWriteStruct(fs);
cvReleaseFileStorage( &fs );
//! [without_base64_flag]
}
{ // [2]
//! [with_write_base64_flag]
CvFileStorage* fs = cvOpenFileStorage( "example.xml", 0, CV_STORAGE_WRITE_BASE64);
// parameter, typename "binary" could be omitted.
cvStartWriteStruct(fs, "rawdata", CV_NODE_SEQ | CV_NODE_FLOW);
cvWriteRawData(fs, rawdata.data(), static_cast<int>(rawdata.size()), "i");
cvEndWriteStruct(fs);
cvReleaseFileStorage( &fs );
//! [with_write_base64_flag]
}
}
int main(int /* argc */, char** /* argv */)
{
{ // base64 mode
CvFileStorage * fs = three_same_ways_of_write_base64();
cvReleaseFileStorage( &fs );
}
{ // output rawdata by `cvWriteRawdata*`
two_ways_to_write_rawdata_in_base64();
}
return 0;
}
+1 -1
View File
@@ -207,7 +207,7 @@ int main( int argc, char** argv )
}
imshow("source", image);
namedWindow("result", CV_WINDOW_NORMAL );
namedWindow("result", WINDOW_NORMAL );
// Create toolbars. HighGUI use.
createTrackbar( "threshold", "result", &sliderPos, 255, processImage );
+1 -1
View File
@@ -50,7 +50,7 @@ int main( int argc, const char** argv )
Rect rect;
minMaxLoc(res, &minVal, &maxVal, &minLoc, &maxLoc);
if(method == CV_TM_SQDIFF || method == CV_TM_SQDIFF_NORMED)
if(method == TM_SQDIFF || method == TM_SQDIFF_NORMED)
rect = Rect(minLoc, tmpl.size());
else
rect = Rect(maxLoc, tmpl.size());
+3 -3
View File
@@ -177,8 +177,8 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade,
circle( img, center, radius, color, 3, 8, 0 );
}
else
rectangle( img, cvPoint(cvRound(r.x*scale), cvRound(r.y*scale)),
cvPoint(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
rectangle( img, Point(cvRound(r.x*scale), cvRound(r.y*scale)),
Point(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
color, 3, 8, 0);
const int half_height=cvRound((float)r.height/2);
@@ -206,7 +206,7 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade,
float intensityZeroOne = ((float)smile_neighbors - min_neighbors) / (max_neighbors - min_neighbors + 1);
int rect_height = cvRound((float)img.rows * intensityZeroOne);
Scalar col = Scalar((float)255 * intensityZeroOne, 0, 0);
rectangle(img, cvPoint(0, img.rows), cvPoint(img.cols/10, img.rows - rect_height), col, -1);
rectangle(img, Point(0, img.rows), Point(img.cols/10, img.rows - rect_height), col, -1);
}
imshow( "result", img );
+1 -1
View File
@@ -312,7 +312,7 @@ int main( int argc, char** argv )
/* Default values to train SVM */
svm->setCoef0( 0.0 );
svm->setDegree( 3 );
svm->setTermCriteria( TermCriteria( CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 1000, 1e-3 ) );
svm->setTermCriteria( TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 1000, 1e-3 ) );
svm->setGamma( 0 );
svm->setKernel( SVM::LINEAR );
svm->setNu( 0.5 );
+2 -2
View File
@@ -189,11 +189,11 @@ static void onMouse( int event, int x, int y, int, void* pData)
switch( event )
{
case CV_EVENT_LBUTTONUP:
case EVENT_LBUTTONUP:
addPointRetrainAndRedraw(data, x, y, 1);
break;
case CV_EVENT_RBUTTONDOWN:
case EVENT_RBUTTONDOWN:
addPointRetrainAndRedraw(data, x, y, -1);
break;
}
@@ -97,7 +97,7 @@ void MatchingMethod( int, void* )
//! [match_template]
/// Do the Matching and Normalize
bool method_accepts_mask = (CV_TM_SQDIFF == match_method || match_method == CV_TM_CCORR_NORMED);
bool method_accepts_mask = (TM_SQDIFF == match_method || match_method == TM_CCORR_NORMED);
if (use_mask && method_accepts_mask)
{ matchTemplate( img, templ, result, match_method, mask); }
else
@@ -36,7 +36,7 @@ int main(int argc, char** argv)
if (src.channels() == 3)
{
cvtColor(src, gray, CV_BGR2GRAY);
cvtColor(src, gray, COLOR_BGR2GRAY);
}
else
{
@@ -50,7 +50,7 @@ int main(int argc, char** argv)
//! [bin]
// Apply adaptiveThreshold at the bitwise_not of gray, notice the ~ symbol
Mat bw;
adaptiveThreshold(~gray, bw, 255, CV_ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, -2);
adaptiveThreshold(~gray, bw, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, -2);
// Show binary image
show_wait_destroy("binary", bw);
@@ -106,7 +106,7 @@ int main(int argc, char** argv)
// Step 1
Mat edges;
adaptiveThreshold(vertical, edges, 255, CV_ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 3, -2);
adaptiveThreshold(vertical, edges, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 3, -2);
show_wait_destroy("edges", edges);
// Step 2
@@ -56,7 +56,7 @@ int main(int argc, char** argv)
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
line( cdst, pt1, pt2, Scalar(0,0,255), 3, LINE_AA);
}
//![draw_lines]
+1 -1
View File
@@ -35,7 +35,7 @@ int main(int, char**)
//--- INITIALIZE VIDEOWRITER
VideoWriter writer;
int codec = CV_FOURCC('M', 'J', 'P', 'G'); // select desired codec (must be available at runtime)
int codec = VideoWriter::fourcc('M', 'J', 'P', 'G'); // select desired codec (must be available at runtime)
double fps = 25.0; // framerate of the created video stream
string filename = "./live.avi"; // name of the output video file
writer.open(filename, codec, fps, src.size(), isColor);