mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 03:33:28 +08: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:
parent
e06d1e8083
commit
7f9253ea0a
@ -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
|
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.
|
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
|
At the same time, it also supports adding parameters like "example.xml?base64".
|
||||||
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
|
|
||||||
|
|
||||||
The function returns a pointer to the CvFileStorage structure.
|
The function returns a pointer to the CvFileStorage structure.
|
||||||
If the file cannot be opened then the function returns NULL.
|
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".
|
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 fs File storage
|
||||||
@param src Pointer to the written array
|
@param src Pointer to the written array
|
||||||
@param len Number of the array elements to write
|
@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
|
//! @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.
|
/** @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
|
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.*
|
* 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_FILLED -1
|
||||||
|
|
||||||
#define CV_AA 16
|
#define CV_AA 16
|
||||||
|
@ -125,6 +125,8 @@ if(MSVC)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_definitions(-DDISABLE_OPENCV_24_COMPATIBILITY=1) # Avoid C-like legacy API
|
||||||
|
|
||||||
add_subdirectory(cpp)
|
add_subdirectory(cpp)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_subdirectory(directx)
|
add_subdirectory(directx)
|
||||||
|
@ -133,7 +133,7 @@ static double rateFrame(Mat & frame)
|
|||||||
unsigned long int sum = 0;
|
unsigned long int sum = 0;
|
||||||
unsigned long int size = frame.cols * frame.rows;
|
unsigned long int size = frame.cols * frame.rows;
|
||||||
Mat edges;
|
Mat edges;
|
||||||
cvtColor(frame, edges, CV_BGR2GRAY);
|
cvtColor(frame, edges, COLOR_BGR2GRAY);
|
||||||
GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
|
GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
|
||||||
Canny(edges, edges, 0, 30, 3);
|
Canny(edges, edges, 0, 30, 3);
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ int main(int argc, char ** argv)
|
|||||||
if (!GlobalArgs.output.empty())
|
if (!GlobalArgs.output.empty())
|
||||||
{
|
{
|
||||||
Size S = Size((int) cap.get(CAP_PROP_FRAME_WIDTH), (int) cap.get(CAP_PROP_FRAME_HEIGHT));
|
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);
|
videoWriter.open(GlobalArgs.output, fourCC, GlobalArgs.fps, S, true);
|
||||||
if (!videoWriter.isOpened())
|
if (!videoWriter.isOpened())
|
||||||
{
|
{
|
||||||
|
@ -218,8 +218,8 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade,
|
|||||||
circle( img, center, radius, color, 3, 8, 0 );
|
circle( img, center, radius, color, 3, 8, 0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rectangle( img, cvPoint(cvRound(r.x*scale), cvRound(r.y*scale)),
|
rectangle( img, Point(cvRound(r.x*scale), cvRound(r.y*scale)),
|
||||||
cvPoint(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
|
Point(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
|
||||||
color, 3, 8, 0);
|
color, 3, 8, 0);
|
||||||
if( nestedCascade.empty() )
|
if( nestedCascade.empty() )
|
||||||
continue;
|
continue;
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -207,7 +207,7 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
|
|
||||||
imshow("source", image);
|
imshow("source", image);
|
||||||
namedWindow("result", CV_WINDOW_NORMAL );
|
namedWindow("result", WINDOW_NORMAL );
|
||||||
|
|
||||||
// Create toolbars. HighGUI use.
|
// Create toolbars. HighGUI use.
|
||||||
createTrackbar( "threshold", "result", &sliderPos, 255, processImage );
|
createTrackbar( "threshold", "result", &sliderPos, 255, processImage );
|
||||||
|
@ -50,7 +50,7 @@ int main( int argc, const char** argv )
|
|||||||
Rect rect;
|
Rect rect;
|
||||||
minMaxLoc(res, &minVal, &maxVal, &minLoc, &maxLoc);
|
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());
|
rect = Rect(minLoc, tmpl.size());
|
||||||
else
|
else
|
||||||
rect = Rect(maxLoc, tmpl.size());
|
rect = Rect(maxLoc, tmpl.size());
|
||||||
|
@ -177,8 +177,8 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade,
|
|||||||
circle( img, center, radius, color, 3, 8, 0 );
|
circle( img, center, radius, color, 3, 8, 0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rectangle( img, cvPoint(cvRound(r.x*scale), cvRound(r.y*scale)),
|
rectangle( img, Point(cvRound(r.x*scale), cvRound(r.y*scale)),
|
||||||
cvPoint(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
|
Point(cvRound((r.x + r.width-1)*scale), cvRound((r.y + r.height-1)*scale)),
|
||||||
color, 3, 8, 0);
|
color, 3, 8, 0);
|
||||||
|
|
||||||
const int half_height=cvRound((float)r.height/2);
|
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);
|
float intensityZeroOne = ((float)smile_neighbors - min_neighbors) / (max_neighbors - min_neighbors + 1);
|
||||||
int rect_height = cvRound((float)img.rows * intensityZeroOne);
|
int rect_height = cvRound((float)img.rows * intensityZeroOne);
|
||||||
Scalar col = Scalar((float)255 * intensityZeroOne, 0, 0);
|
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 );
|
imshow( "result", img );
|
||||||
|
@ -312,7 +312,7 @@ int main( int argc, char** argv )
|
|||||||
/* Default values to train SVM */
|
/* Default values to train SVM */
|
||||||
svm->setCoef0( 0.0 );
|
svm->setCoef0( 0.0 );
|
||||||
svm->setDegree( 3 );
|
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->setGamma( 0 );
|
||||||
svm->setKernel( SVM::LINEAR );
|
svm->setKernel( SVM::LINEAR );
|
||||||
svm->setNu( 0.5 );
|
svm->setNu( 0.5 );
|
||||||
|
@ -189,11 +189,11 @@ static void onMouse( int event, int x, int y, int, void* pData)
|
|||||||
|
|
||||||
switch( event )
|
switch( event )
|
||||||
{
|
{
|
||||||
case CV_EVENT_LBUTTONUP:
|
case EVENT_LBUTTONUP:
|
||||||
addPointRetrainAndRedraw(data, x, y, 1);
|
addPointRetrainAndRedraw(data, x, y, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CV_EVENT_RBUTTONDOWN:
|
case EVENT_RBUTTONDOWN:
|
||||||
addPointRetrainAndRedraw(data, x, y, -1);
|
addPointRetrainAndRedraw(data, x, y, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ void MatchingMethod( int, void* )
|
|||||||
|
|
||||||
//! [match_template]
|
//! [match_template]
|
||||||
/// Do the Matching and Normalize
|
/// 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)
|
if (use_mask && method_accepts_mask)
|
||||||
{ matchTemplate( img, templ, result, match_method, mask); }
|
{ matchTemplate( img, templ, result, match_method, mask); }
|
||||||
else
|
else
|
||||||
|
@ -36,7 +36,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
if (src.channels() == 3)
|
if (src.channels() == 3)
|
||||||
{
|
{
|
||||||
cvtColor(src, gray, CV_BGR2GRAY);
|
cvtColor(src, gray, COLOR_BGR2GRAY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ int main(int argc, char** argv)
|
|||||||
//! [bin]
|
//! [bin]
|
||||||
// Apply adaptiveThreshold at the bitwise_not of gray, notice the ~ symbol
|
// Apply adaptiveThreshold at the bitwise_not of gray, notice the ~ symbol
|
||||||
Mat bw;
|
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 binary image
|
||||||
show_wait_destroy("binary", bw);
|
show_wait_destroy("binary", bw);
|
||||||
@ -106,7 +106,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
// Step 1
|
// Step 1
|
||||||
Mat edges;
|
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);
|
show_wait_destroy("edges", edges);
|
||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
|
@ -56,7 +56,7 @@ int main(int argc, char** argv)
|
|||||||
pt1.y = cvRound(y0 + 1000*(a));
|
pt1.y = cvRound(y0 + 1000*(a));
|
||||||
pt2.x = cvRound(x0 - 1000*(-b));
|
pt2.x = cvRound(x0 - 1000*(-b));
|
||||||
pt2.y = cvRound(y0 - 1000*(a));
|
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]
|
//![draw_lines]
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ int main(int, char**)
|
|||||||
|
|
||||||
//--- INITIALIZE VIDEOWRITER
|
//--- INITIALIZE VIDEOWRITER
|
||||||
VideoWriter writer;
|
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
|
double fps = 25.0; // framerate of the created video stream
|
||||||
string filename = "./live.avi"; // name of the output video file
|
string filename = "./live.avi"; // name of the output video file
|
||||||
writer.open(filename, codec, fps, src.size(), isColor);
|
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;
|
std::vector<cv::Rect> facesColl;
|
||||||
cv::Mat frame_gray;
|
cv::Mat frame_gray;
|
||||||
|
|
||||||
cvtColor(groupFaces, frame_gray, CV_BGR2GRAY);
|
cvtColor(groupFaces, frame_gray, COLOR_BGR2GRAY);
|
||||||
cv::equalizeHist(frame_gray, frame_gray);
|
cv::equalizeHist(frame_gray, frame_gray);
|
||||||
|
|
||||||
// Detect faces
|
// Detect faces
|
||||||
|
Loading…
Reference in New Issue
Block a user