我正在尝试使用AVFoundation中的类来获取视频的第一帧.但它似乎根本没有得到一个图像.
我的代码目前看起来像这样
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:videoPath] options:nil];
AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
UIImage* image = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]];
[videoFrame setImage:image];
Run Code Online (Sandbox Code Playgroud)
视频路径的价值/var/mobile/Applications/02F42CBF-D8BD-4155-85F2-8CF1E55B5023/Documents/videos/1334300431637030.mp4绝对是一个视频,因为我可以播放它MPMoviePlayerViewController.我不确定我做错了什么,但任何建议都会有所帮助.
谢谢.
我有一个UIImage,我从UIImagePickerController获取.当我从- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info方法中收到图像时,我将其直接放入UIImageView进行预览,并为用户提供保存或丢弃图像的选项.

当用户选择保存选项时,应用程序获取图像的png数据并将其保存到文档目录中.但是在2种可能的设备方向之一(仅景观)下发生的事情是图像被颠倒保存(更具体地说,从它应该的位置旋转180度).因此,当我在图库中加载图像时,它会显示为颠倒.
(参见图库中的左下角图片)

我已经解决了UIImage来自UIImage的UIImage中的原始图像数据没有旋转,而是将方向存储为对象的属性,仅在显示时应用.所以我试图使用我在网上找到的一些代码来旋转与UIImage相关联的CGImage.但它似乎对图像完全没有影响.我正在使用的代码如下:
- (void)rotateImage:(UIImage*)image byRadians:(CGFloat)rads
{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,image.size.width, image.size.height)];
CGAffineTransform t = CGAffineTransformMakeRotation(rads);
rotatedViewBox.transform = t;
CGSize rotatedSize = rotatedViewBox.frame.size;
// Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
// Move the origin to the middle of the image you want to rotate and scale around the center.
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
// Rotate …Run Code Online (Sandbox Code Playgroud) 我有一个封闭的凸多面体,它是由一个凸多边形(面)阵列定义的,这些多边形由三维空间中的顶点数组定义.假设密度均匀,我试图找到多面体的质心.目前我用这个伪代码中的算法计算它.
public Vector3 getCentroid() {
Vector3 centroid = (0, 0, 0);
for (face in faces) {
Vector3 point = face.centroid;
point.multiply(face.area());
centroid.add(point);
}
centroid.divide(faces.size());
return centroid;
}
Run Code Online (Sandbox Code Playgroud)
这基本上取面的质心的加权平均值.我不是100%确定这是正确的,因为我无法在线找到正确的算法.如果有人可以确认我的算法或引用我一个正确的算法我会很感激.
谢谢.
[编辑]
所以这是我用来查找质心的实际Java代码.它将多面体分解为会聚在多面体内任意点上的金字塔.金字塔质心的加权平均值基于以下公式.
C all = SUM 所有金字塔(C 金字塔*体积金字塔)/体积全部
这里是(大量注释的代码):
// Compute the average of the facial centroids.
// This gives an arbitrary point inside the polyhedron.
Vector3 avgPoint = new Vector3(0, 0, 0);
for (int i = 0; i < faces.size(); i++) {
avgPoint.add(faces.get(i).centroid); …Run Code Online (Sandbox Code Playgroud) 我正在使用Java,但我想这个问题适用于任何语言.我只是想问一下,使用布尔值退出循环是更好的做法,我在循环中切换或只使用break;
例如,我只是在写一个方法来获得国际象棋中女王的有效动作.
private static final int[][] DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
public Vector<Move> getValidMoves() {
Vector<Move> validMoves = new Vector<Move>();
for (int i = 0; i < DIRS.length; i++) {
boolean stopped = false;
int newX = x + DIRS[i][0];
int newY = y + DIRS[i][1];
while (!stopped && newX >= 0 && newX < 8 && newY >= 0 && newY < 8) {
if (board[newX][newY] …Run Code Online (Sandbox Code Playgroud) 我有一张表格,记录了问题、他们的答案和他们的作者。列名如下:
ID,问题,答案,作者
我想得到一个写出最多问题的前 10 位作者的列表。因此,它需要首先计算每个作者写的问题数量,然后按数量对它们进行排序,然后返回前 10 个。
这是在 SQLite 中,我不确定如何获取计数列表。第二部分应该相当简单,因为它只是一个ORDER BY和一个LIMIT 10。如何将计数放入我可以选择的列表中?
我在3D空间中有一个2D凸多边形和一个测量多边形面积的函数.
public double area() {
if (vertices.size() >= 3) {
double area = 0;
Vector3 origin = vertices.get(0);
Vector3 prev = vertices.get(1).clone();
prev.sub(origin);
for (int i = 2; i < vertices.size(); i++) {
Vector3 current = vertices.get(i).clone();
current.sub(origin);
Vector3 cross = prev.cross(current);
area += cross.magnitude();
prev = current;
}
area /= 2;
return area;
} else {
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
为了测试这个方法适用于多边形的所有方向,我的程序每次迭代都会旋转一点并计算面积.像这样......
Face f = poly.getFaces().get(0);
for (int i = 0; i < f.size(); i++) {
Vector3 v = f.getVertex(i); …Run Code Online (Sandbox Code Playgroud) java ×3
ios ×2
math ×2
objective-c ×2
avfoundation ×1
cgimage ×1
coding-style ×1
geometry ×1
physics ×1
select ×1
sql ×1
sqlite ×1
top-n ×1
uiimage ×1
vector ×1