我有一个图像,想用OpenH264对其进行编码。
到目前为止,这是我从他们的维基派生的代码:
#include <fstream>
#include <iterator>
#include <iostream>
#include <codec_api.h> //standard api for openh264
//additional libaries used by sample code
#include <codec_app_def.h>
#include <codec_def.h>
#include <codec_ver.h>
#include <assert.h>
#include <vector>
#include <cstring>
int main()
{
//parameter values
int width = 1920;
int height = 1080;
int framerate = 60;
int bitrate = 5000000;
int total_num = 500; //what does this value do?
//end parameter values
//Read in the File from bmp
std::vector<char> buf; //to store the …Run Code Online (Sandbox Code Playgroud) 给出了两种数据类型Color和Plant.
data Color = Red | Pink | White | Blue | Purple | Green | Yellow
deriving (Show, Eq)
data Plant =
Leaf
| Blossom Color
| Stalk Plant Plant
deriving (Show, Eq)
Run Code Online (Sandbox Code Playgroud)
现在我应该实现fold_plant以下类型的功能:
(x -> x -> x) -> (Color -> x) -> x -> Plant -> x
Run Code Online (Sandbox Code Playgroud)
我理解折叠函数的方式是它需要一个列表,并且对于每次迭代,它从列表中删除第一个元素并对该元素执行某些操作.
显然fold_plant Stalk Blossom Leaf是植物的身份.
现在我知道在Haskell中你可以创建这样的函数:
fold_plant :: (x -> x -> x) -> (Color -> x) -> x -> Plant -> x
fold_plant = do …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个函数,它将给定列表中的所有数字相加,然后将其除以6.
average :: [Integer] -> Integer
average m = (sum m) quot 6
Run Code Online (Sandbox Code Playgroud)
但这是我收到的错误消息:
Couldn't match type `Integer'
with `(a0 -> a0 -> a0) -> a1 -> Integer'
Expected type: [(a0 -> a0 -> a0) -> a1 -> Integer]
Actual type: [Integer]
In the first argument of `sum', namely `m'
In the expression: (sum m) quot 6
Run Code Online (Sandbox Code Playgroud) 这是功能:
f [] = []
f (h:t) = (\x -> x - h) : f t
Run Code Online (Sandbox Code Playgroud)
它接受一个列表并返回一个匿名函数列表,它们从x中减去每个元素.
显然有一些方法可以用20个字符或更少的字符写这个整个函数.
我试着这样做,map但只是将一个函数应用于列表的每个元素.我也试图替换(-a)无效的匿名函数.
有人有想法吗?