提交 7f9253ea 编写于 作者: A Alexander Alekhin

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
上级 e06d1e80
......@@ -1978,11 +1978,7 @@ The function opens file storage for reading or writing data. In the latter case,
created or an existing file is rewritten. The type of the read or written file is determined by the
filename extension: .xml for XML, .yml or .yaml for YAML and .json for JSON.
At the same time, it also supports adding parameters like "example.xml?base64". The three ways
are the same:
@snippet samples/cpp/filestorage_base64.cpp suffix_in_file_name
@snippet samples/cpp/filestorage_base64.cpp flag_write_base64
@snippet samples/cpp/filestorage_base64.cpp flag_write_and_flag_base64
At the same time, it also supports adding parameters like "example.xml?base64".
The function returns a pointer to the CvFileStorage structure.
If the file cannot be opened then the function returns NULL.
......@@ -2206,11 +2202,6 @@ in plain text.
This function can only be used to write a sequence with a type "binary".
Consider the following two examples where their output is the same:
@snippet samples/cpp/filestorage_base64.cpp without_base64_flag
and
@snippet samples/cpp/filestorage_base64.cpp with_write_base64_flag
@param fs File storage
@param src Pointer to the written array
@param len Number of the array elements to write
......
......@@ -4339,6 +4339,10 @@ CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, InputArray user
//! @addtogroup imgproc_draw
//! @{
/** OpenCV color channel order is BGR[A] */
#define CV_RGB(r, g, b) cv::Scalar((b), (g), (r), 0)
/** @brief Draws a line segment connecting two points.
The function line draws the line segment between pt1 and pt2 points in the image. The line is
......
......@@ -982,7 +982,6 @@ CVAPI(void) cvFitLine( const CvArr* points, int dist_type, double param,
* If a drawn figure is partially or completely outside of the image, it is clipped.*
\****************************************************************************************/
#define CV_RGB( r, g, b ) cvScalar( (b), (g), (r), 0 )
#define CV_FILLED -1
#define CV_AA 16
......
......@@ -125,6 +125,8 @@ if(MSVC)
endif()
endif()
add_definitions(-DDISABLE_OPENCV_24_COMPATIBILITY=1) # Avoid C-like legacy API
add_subdirectory(cpp)
if(WIN32)
add_subdirectory(directx)
......
......@@ -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())
{
......
......@@ -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;
......
#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;
}
......@@ -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 );
......
......@@ -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());
......
......@@ -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 );
......
......@@ -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 );
......
......@@ -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]
......
......@@ -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);
......
......@@ -63,7 +63,7 @@ void FaceDetection::MainPage::detectBtn_Click(Platform::Object^ sender, Windows:
std::vector<cv::Rect> facesColl;
cv::Mat frame_gray;
cvtColor(groupFaces, frame_gray, CV_BGR2GRAY);
cvtColor(groupFaces, frame_gray, COLOR_BGR2GRAY);
cv::equalizeHist(frame_gray, frame_gray);
// Detect faces
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册