Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
17 changes: 17 additions & 0 deletions Binary_Search
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
template<typename Iter,typename T>
bool _binary_search(Iter beg,Iter end,const T& val)
{
Iter m,_beg;
std::sort(beg ,end); //先从小到大排序
end=end-1;
_beg=beg; //指针无法参与算术运算,保存首地址
while(beg<=end)
{
m=_beg+(beg-_beg)/2+(end-_beg)/2+((beg-_beg)%2&(end-_beg)%2);
if((*m)==val)
return true;
else if(*m>val)
end=m-1;
else if(*m<val)
beg=m+1;
}
25 changes: 25 additions & 0 deletions Compile_Folly
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
git clone https://github.com/facebook/folly
git clone https://github.com/google/googletest/archive/release-1.8.0.tar.gz
tar zxf release-1.8.0.tar.gz
rm -f release-1.8.0.tar.gz
cd googletest-release-1.8.0
cmake .
make
sudo make install
sudo apt-get install libboost-all-dev
sudo apt-get install libevent-dev
sudo apt-get install libdouble-conversion-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install libgflags-dev
sudo apt-get install libiberty-dev
sudo apt-get install liblzma-dev
sudo apt-get install libsnappy-dev
sudo apt-get install libssl-dev
sudo apt-get install libunwind8-dev
sudo apt-get install libelf-dev
sudo apt-get install libdwarf-dev
mkdir _build && cd _build
cmake ..
make -j4
sudo make install

10 changes: 10 additions & 0 deletions LeetCode.189
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
public:
void rotate(std::vector<int>& nums, int k) {
//反转法
k %= nums.size();
std::reverse(nums.begin(), nums.end());
std::reverse(nums.begin(),nums.begin()+k);
std::reverse(nums.begin()+k, nums.end());
}
};
11 changes: 11 additions & 0 deletions LeetCode.268
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution {
public:
int missingNumber(vector<int> nums) {
std::sort(nums.begin(),nums.end());
int i;
for( i=0;i<nums.size();i++)
if(nums[i]!=i)
break;
return i;
}
};
Binary file added MSER/1_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MSER/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MSER/2_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MSER/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added MSER/3_out.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions MSER/MSER.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
namespace sp
{

float iou(const cv::Rect& lhs, const cv::Rect& rhs)
{
const int lt_x = std::max(lhs.x, rhs.x);
const int lt_y = std::max(lhs.y, rhs.y);
const int rd_x = std::min(lhs.x + lhs.width, rhs.x + rhs.width);
const int rd_y = std::min(lhs.y + lhs.height, rhs.y + rhs.height);

const int inner_w = std::max(0, rd_x - lt_x + 1);
const int inner_h = std::max(0, rd_y - lt_y + 1);
const int inner_area = inner_h * inner_w;

return static_cast<float>(inner_area) / (lhs.area() + rhs.area() - inner_area);
}

}

int main()
{
auto mat = cv::imread("test.jpg", cv::IMREAD_GRAYSCALE);
cv::resize(mat, mat, {1280, 720});
auto mser = cv::MSER::create(8,85,10000,0.1);
/*修改MSER算法中初始设置的参数,使既减少
BBOXES数量又不遗漏数字,且适用于不同图片*/
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Rect> bboxes;

mser->detectRegions(mat, contours, bboxes);
std::cout << bboxes.size() << '\n';
std::cin.get();

std::vector<int> drawed_rects;
drawed_rects.reserve(bboxes.size() / 4);

int cnt = 0;
if (!bboxes.empty())
{
++cnt;
cv::rectangle(mat, bboxes.front(), {255, 0, 0});
drawed_rects.push_back(0);
}
constexpr float thresh = 0.5;
int prop=8;//设置矩形长宽比界限
for (int i = 1; i < bboxes.size(); ++i)
{
bool skip = false;
for (auto&& index : drawed_rects)
if (skip = (sp::iou(bboxes[i], bboxes[index]) > thresh))
break;
if (skip)
continue;
if((bboxes[i].width/bboxes[i].height)>=prop||(bboxes[i].height/bboxes[i].width)>=prop)
continue;//超过长宽比就舍弃
cv::rectangle(mat, bboxes[i], { 255, 0, 0 });
drawed_rects.push_back(i);
++cnt;
}

std::cout << cnt << '\n';
std::cin.get();
cv::imwrite("test_out.jpg", mat);
}
46 changes: 46 additions & 0 deletions VideoCapture_threshold
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"

using namespace cv;
using namespace std;

void to_GrayImage(Mat &Image,Mat &GrayImage);//转灰度图

int main()
{
cout << "Built with OpenCV " << CV_VERSION << endl;
Mat Image,GrayImage,BinaryImage;
VideoCapture capture;
capture.open(0);
if(capture.isOpened())
{
cout << "Capture is opened" << endl;
for(;;)
{
capture >> Image;
if(Image.empty())
break;
to_GrayImage(Image,GrayImage);
threshold(GrayImage,BinaryImage,100,255,THRESH_BINARY);
imshow("Sample", BinaryImage);
if(waitKey(10) >= 0)
break;
}
}
else
{
cout << "No capture" << endl;
Image = Mat::zeros(480, 640, CV_8UC1);
imshow("Sample", Image);
waitKey(0);
}
return 0;
}
void to_GrayImage(Mat &Image,Mat &GrayImage)
{
GrayImage.create(Image.size(),Image.type());
cvtColor(Image,GrayImage,COLOR_BGR2GRAY);
}
34 changes: 34 additions & 0 deletions prop_thre.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//(1)namespace局部命名空间可以有效避免项目协作时因函数等命名相同造成冲突
/*(2)具体操作应该打包成函数,而且不能随意在函数过程中给变量赋值,如比例等,
这样修改比较麻烦*/
/*(3).at(j,i)访问制定行与列,但由于像素存储按行存储,而且存在行与行之间有距离
与无距离两种情况,所以用.ptr(uchar)(i)访问每行首地址更准确*/
//(4).at(j+1,i+1)是我错误的认为像素坐标是从(1,1)开始
//(5)程序中定义过多变量,而且程序写的冗长,多是使用最基本的C++语句
//看书不是太多,自己需要多看多学多用
#pragma once
#include <opencv2/opencv.hpp>
namespace zjx
{
void prop_thre(cv::Mat& src_in,cv::Mat&src_out,double proproportion )
{
int image1[256]={0},threshold_val=255;
uint32_t iter_rows =src_in.isContinuous() ? 1 : src_in.rows;
uint32_t iter_cols=src_in.rows*src_in.cols/iter_rows;

for(size_t i=0;i<iter_rows;i++)
{ auto row_ptr=src_in.ptr<uchar>(i);
for(std::size_t j=0;j<iter_cols;++j)
{++image1[*row_ptr++];}
}
int num=iter_rows*iter_cols* proproportion;
while(num>0)
num-=image1[--threshold_val];

threshold(src_in,src_out,threshold_val,255,cv::THRESH_BINARY);
imshow("thre_im",src_out);
cv::waitKey(0);
}
}


27 changes: 27 additions & 0 deletions proportion_thresh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main( )
{
Mat Image,BinaryImage;
Image=imread("1.jpg",cv::IMREAD_GRAYSCALE);
int Image1[256]={0};
uchar ThresholdVal;
int num=0;
for(int i=0;i<Image.cols;i++)
for(int j=0;j<Image.rows;j++)
{
Image1[Image.at<uchar>(j+1,i+1)]++;//将像素值作为数组下标,记录同像素数量
}
for(int i=255;i>=0;i--)
{num+=Image1[i];
if(num>=int(Image.rows*Image.cols*(0.14)))
{ThresholdVal=i+1;
break;
}
}

threshold(Image,BinaryImage,ThresholdVal,255,THRESH_BINARY);
imshow("imgae",BinaryImage);
waitKey(0);
}
19 changes: 19 additions & 0 deletions superpower19classifier-zjx/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include",
"/usr/local/include/opencv4",
"/usr/local/include/opencv4/opencv2"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
29 changes: 29 additions & 0 deletions superpower19classifier-zjx/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.o",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
57 changes: 57 additions & 0 deletions superpower19classifier-zjx/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"files.associations": {
"ostream": "cpp",
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"ratio": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
}
}
35 changes: 35 additions & 0 deletions superpower19classifier-zjx/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.o",
"-I", "/usr/local/include",
"-I", "/usr/local/include/opencv4",
"-I", "/usr/local/include/opencv4/opencv2",
"-L", "/usr/local/lib",
"-l", "opencv_core",
"-l", "opencv_imgproc",
"-l", "opencv_imgcodecs",
"-l", "opencv_video",
"-l", "opencv_ml",
"-l", "opencv_highgui",
"-l", "opencv_objdetect",
"-l", "opencv_flann",
"-l", "opencv_imgcodecs",
"-l", "opencv_photo",
"-l", "opencv_videoio",
"-l","opencv_features2d"
],
"options": {
"cwd": "/usr/bin"
}
}
],
"version": "2.0.0"
}
Loading