以下是使用C++实现双边网格滤波算法的示例代码,不依赖于任何第三方库:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
// 双边滤波器
#=============================================================================== | |
# Filename: boost.sh | |
# Author: Pete Goodliffe | |
# Copyright: (c) Copyright 2009 Pete Goodliffe | |
# Licence: Please feel free to use this, with attribution | |
# Modified version | |
#=============================================================================== | |
# | |
# Builds a Boost framework for the iPhone. | |
# Creates a set of universal libraries that can be used on an iPhone and in the |
Syntax: x264 [options] -o outfile infile [widthxheight] | |
Infile can be raw YUV 4:2:0 (in which case resolution is required), | |
or YUV4MPEG 4:2:0 (*.y4m), | |
or Avisynth if compiled with support (no). | |
or libav* formats if compiled with lavf support (no) or ffms support (no). | |
Outfile type is selected by filename: | |
.264 -> Raw bytestream | |
.mkv -> Matroska | |
.flv -> Flash Video |
// capture image from webcam(e.g. face time) | |
// for OSX 10.9 (use AVFoundation API instead of deprecated QTKit) | |
// clang -fobjc-arc -Wall -Wextra -pedantic avcapture.m | |
// -framework Cocoa -framework AVFoundation -framework CoreMedia | |
// -framework QuartzCore -o avcapture | |
#import <AVFoundation/AVFoundation.h> | |
#import <AppKit/AppKit.h> | |
@interface Capture : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate> |
以下是使用C++实现双边网格滤波算法的示例代码,不依赖于任何第三方库:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
// 双边滤波器
以下是一种较为复杂的自动白平衡算法,称为“灰度世界假设”(Gray World Assumption): | |
1. 将图像转换为LAB颜色空间。 | |
2. 对于每个像素,计算其在LAB颜色空间中的L, a, b值。 | |
3. 计算图像的平均L, a, b值。 | |
4. 将平均值的a, b值分别设置为0,保持平均值的L值不变。 |
以下是使用Lambda表达式将C++的list转换为map的示例代码:
#include <iostream>
#include <list>
#include <map>
#include <string>
using namespace std;
可以使用C++标准库中的vector
来实现一个简单的2维卷积函数。以下是一个示例代码:
#include <iostream>
#include <vector>
using namespace std;
// 二维卷积函数
vector<vector<int>> conv2d(const vector<vector<int>>& img, const vector<vector<int>>& kernel)
在C++中,可以使用二分查找的思想来找到两个有序数组的中值。具体步骤如下:
在C++中,可以使用递归的方式来反转链表。具体步骤如下:
reverseList
,该函数接收一个指向链表头节点的指针head
作为参数,并返回反转后的链表头节点的指针。head
。reverseList
函数来反转剩余的链表,并将返回的反转后的链表头节点的指针保存在变量newHead
中。next
指针指向当前节点,即将当前节点的下一个节点指向当前节点,实现反转。next
指针置空,即将当前节点的下一个节点置空,防止形成环。newHead
作为反转后的链表头节点的指针。下面是使用C++实现的代码:
题目描述:
给定一个非负整数数组 height
表示一系列柱子的高度,每个柱子的宽度为 1。计算下雨后,能够在这些柱子之间存储多少雨水。
例子:
输入:height = [0,1,0,2,1,0,1,3,2,1,2,1]
输出:6
解释:如下图所示,灰色区域表示可以存储雨水的地方,可以存储的雨水量为 6 个单位。
|