我试图在OpenCV中使用人物检测功能:
cv::HOGDescriptor hog;
hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector());
std::vector<cv::Rect> found;
hog.detectMultiScale(noMask, found, 0.2, cv::Size(8,8), cv::Size(16,16), 1.05, 2);
Run Code Online (Sandbox Code Playgroud)
但我得到以下断言:
OpenCV错误:在computeGradient中,断言失败(img.type()== CV_8U || img.type()== CV_8UC3),文件/ Users/robin/Projects/OpenCVForiPhone/opencv/opencv/modules/objdetect/src/hog. cpp,第174行
这是有道理的,因为我传递的是CV_8UC4图像.
所以我猜我应该创造一个具有这种特性的cvmat.现在我有这两种方法.这让我得到灰色或彩色cvmats(CV_8UC1/CV_8UC4)
对于颜色:
-(cv::Mat)CVMat
{
CGColorSpaceRef colorSpace = CGImageGetColorSpace(self.CGImage);
CGFloat cols = self.size.width;
CGFloat rows = self.size.height;
cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels
CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to backing data
cols, // Width of bitmap
rows, // Height of bitmap
8, // Bits per component
cvMat.step[0], // Bytes per row
colorSpace, // …Run Code Online (Sandbox Code Playgroud) 我可能会混淆区域监控的工作原理,但这是我到目前为止所做的:
我正在通过我的位置管理器注册要监视的区域,该位置管理器是在单例类上实现的,此单例也被设置为位置管理器的委托,因此正在调用实现的方法.
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
Run Code Online (Sandbox Code Playgroud)
这完全按预期工作,如果应用程序处于活动状态或暂停状态,则调用该方法.它也很有意义,因为该类已经被加载,当该区域进入事件时,iOS会将此甚至发送到我的应用程序,该应用程序调用已注册的位置管理器(可能有一个引用它),然后它调用任何委托也是沿着它注册(因为课程已准备好并加载).
问题是,应用程序被杀后会发生什么?它是第一次进入后台吗?iOS如何知道要调用的委托方法,以及它是否已经加载?
我有一个问题,我只是无法搞清楚.我有一个应用程序完成,将从前面拍摄一张照片,从后置照相机拍摄一张照片,然后将它们合并在一起.
该应用程序的名称是GroupCam
但是我有一个问题,我的UIButtons从一开始就不会作为视网膜图像加载.如果我在界面构建器上将它们设置为@ 2x它们确实以高质量显示,但是一旦我以编程方式重新加载它们,则会出现低版本.
这是因为在拍摄照片并且屏幕改变后按钮图像改变,但是当用户按下后退按钮时,相机图标看起来很糟糕(因为正在加载低质量版本).
请查看以下图片:
第一个屏幕: 只有右上角按钮显示失真,因为我正在检查相机闪光灯的值并以编程方式"加载"相应的图像.

第二个屏幕: 用户已移动到另一个屏幕并返回到第一个屏幕,所有按钮都重新加载,现在它们看起来都很扭曲.

如果有人知道为什么会发生这种情况,我会非常感激!
谢谢.
编辑:
这是我加载图像的方式.
[self.flashButton setImage:[UIImage imageNamed:@"flashOff"]
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
我在互联网上的某处读到,这样做会自动加载最合适的图像版本.
我也尝试了这个,但结果是一样的:
[self.takeButton setImage:[UIImage imageNamed:@"takePhoto.png"] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud) 我正在尝试将图片发送到我的java servlet(托管在amazon ec2上)以便稍后将其传输到amazon s3并且想知道如何从post请求中检索图像.
请求通过iOS RestKit API发送(pic.imageData是NSData类型):
RKParams* params = [RKParams params];
[params setValue:pic.dateTaken forParam:@"dateTaken"];
[params setValue:pic.dateUploaded forParam:@"dateUploaded"];
[params setData:pic.imageData MIMEType:@"image/jpeg" forParam:@"image"];
[RKClient sharedClient].username = deviceID;
[RKClient sharedClient].password = sessionKey;
[RKClient sharedClient].authenticationType = RKRequestAuthenticationTypeHTTPBasic;
uploadPictureRequest = [[RKClient sharedClient] post:kUploadPictureServlet params:params delegate:self];
Run Code Online (Sandbox Code Playgroud)
这是我解析Java servlet上其他2个参数的方法:
double dateTaken = Double.parseDouble(req.getParameter("dateTaken"));
double dateUploaded = Double.parseDouble(req.getParameter("dateUploaded"));
Run Code Online (Sandbox Code Playgroud)
问题是:如何在服务器上检索和解析图像?
我试图在Interface Builder中为我的标签选择"系统字体".所有这些标签都包含属性字符串.如果它们是"痛苦标签",我可以轻松选择"系统字体",我的应用程序将自动使用iOS 8的"Helvetica"和iOS 9+的"旧金山".
问题是,使用属性字符串时似乎不可能.(我需要它们用于线之间的间距).
即使我要下载字体并在界面构建器中选择一个字体,它也不会像"纯文本"标签那样根据iOS自动更改.
有没有办法实现这个目标?也许我错过了什么.
顺便说一句,我目前的工作是将所有标签连接到一个插座阵列并循环创建NSMutableAttributedString,然后用编程检索的系统字体"覆盖"字体属性.
这样做的缺点是标签创建了两次,因此在具有大量标签的屏幕上会变慢.
编辑:我用来"更改"字体的代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
for label in labelsToFormat {
let targetFont = UIFont.systemFont(ofSize: label.font.pointSize)
let originalLabel = NSMutableAttributedString(attributedString: label.attributedText!)
originalLabel.addAttribute(NSFontAttributeName, value: targetFont, range: NSMakeRange(0, originalLabel.length))
label.attributedText = originalLabel
}
for label in labelsToFormatBold {
let targetFont = UIFont.boldSystemFont(ofSize: label.font.pointSize)
let originalLabel = NSMutableAttributedString(attributedString: label.attributedText!)
originalLabel.addAttribute(NSFontAttributeName, value: targetFont, range: NSMakeRange(0, originalLabel.length))
label.attributedText = originalLabel
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码创建我的请求:
let textRequest = VNDetectTextRectanglesRequest(completionHandler:
self.detectTextHandler)
textRequest.reportCharacterBoxes = true
self.requests = [textRequest]
Run Code Online (Sandbox Code Playgroud)
在我的AVCaptureVideoDataOutputSampleBufferDelegate 中,我正在创建一个 VNImageRequestHandler 并执行它:
let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: CGImagePropertyOrientation(rawValue: 6)!, options: requestOptions)
do {
try imageRequestHandler.perform(self.requests)
} catch {
print(error)
}
Run Code Online (Sandbox Code Playgroud)
这为我提供了具有以下签名的处理程序内部的检测结果:
func detectTextHandler(request: VNRequest, error: Error?)
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何获得此请求用于进一步处理的“cvPixelBuffer”?我应该存储它的临时版本吗?
我正在编写一个统一插件来将原生 iOS 功能连接到 Unity。
我必须做的一件事是将字符串从 Objective-C(iOS) 发送回 C#(Unity),这是通过编写一个简单的 C extern 函数来完成的。
我找到了这个帖子:
https://forum.unity3d.com/threads/plugins-sending-string-data.66435/
这建议使用这个可以通过 C extern 返回的辅助函数:
// Helper method to create C string copy
char* MakeStringCopy (const char* string)
{
if (string == NULL)
return NULL;
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}
Run Code Online (Sandbox Code Playgroud)
我对 Unity 不是很精通,所以我不知道这是否导致内存泄漏。
从纯Objective-C的角度来看,函数
辅助函数在 C extern 函数中使用,如下所示:
return cStringCopy([objc_status UTF8String]);
Run Code Online (Sandbox Code Playgroud)
所以原始字符串使用的内存由Objective-C自动管理,但是......
一旦Unity收到char指针,它会自动释放分配的内存吗?
C# unity 脚本使用如下函数:
string someInfo = SDKWrapper_getInfo();
Run Code Online (Sandbox Code Playgroud)
这个问题的答案:
有点与此有关(我认为),所以它真的让我觉得我在这里有内存泄漏。
您好我已尽力了解代码的这部分内容,但我没有运气.
glGenVertexArraysOES(1, &_vertexArray);
glBindVertexArrayOES(_vertexArray);
glGenBuffers(1, &_vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW);
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
glBindVertexArrayOES(0);
Run Code Online (Sandbox Code Playgroud)
这属于在xcode 4.2上创建OpenGL游戏的模板.但是我很困惑,如果有人能向我解释,我会很高兴.
首先,如何生成并绑定_vertexArray而不向其添加任何内容?
其次,IF gCubeVertexData是216的数组,具有以下内容:
GLfloat gCubeVertexData[216] =
{
// Data layout for each line below is:
// positionX, positionY, positionZ, normalX, normalY, normalZ,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
Run Code Online (Sandbox Code Playgroud)
我想我正在为以下命令处理这个数组,其中我启用GLK属性,这就是我使用指针(仍然使用prev绑定的).但是,如果我没有弄错的语法是,(属性设置,顶点的大小,类型,假,结构的大小(我认为不是24),并从数据偏移(12来自哪里?!))
最后一个问题,为什么我现在将0绑定到顶点数组?
编辑:要诚实我DID尝试在各个站点研究opengl但我只能遇到理论而不是实践.这就是我问这个问题的原因.
我想做一些非常简单的事情.我希望以全屏显示视频图层,并且每秒更新一次使用当时获得的CMSampleBufferRef的UIImage.但是我遇到了两个不同的问题.第一个是改变:
[connection setVideoMaxFrameDuration:CMTimeMake(1, 1)];
[connection setVideoMinFrameDuration:CMTimeMake(1, 1)];
Run Code Online (Sandbox Code Playgroud)
还会修改视频预览图层,我认为它只会修改av foundation将信息发送给委托的速率,但它似乎会影响整个会话(看起来更加明显).所以这使我的视频每秒更新一次.我想我可以省略这些行,只需在委托中添加一个计时器,以便每秒将CMSampleBufferRef发送到另一个方法来处理它.但如果这是正确的方法,我不知道.
我的第二个问题是UIImageView没有更新,或者有时它只更新一次并且之后没有更改.我正在使用此方法来更新它:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
//NSData *jpeg = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:sampleBuffer] ;
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
[imageView setImage:image];
// Add your code here that uses the image.
NSLog(@"update");
}
Run Code Online (Sandbox Code Playgroud)
我从苹果的例子中得到了什么.通过读取更新消息检查每秒正确调用该方法.但图像根本没有变化.sampleBuffer也是自动销毁还是我必须释放它?
这是另外两个重要的方法:查看载入:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
session = [[AVCaptureSession alloc] init];
// Add inputs and outputs.
if ([session canSetSessionPreset:AVCaptureSessionPreset640x480]) {
session.sessionPreset = AVCaptureSessionPreset640x480;
}
else …Run Code Online (Sandbox Code Playgroud) 我的问题很简单,我想知道方法"CGImageSourceCreateWithData"是否创建了一个复制我提供的数据的新对象,以便在我不再需要它时,我必须释放它,或者它只是创建一个引用我已经拥有的数据,如果我发布它,我将丢失这些数据(并可能有错误的访问错误).
该问题与使用(__bridge CFDataRef)作为源数据有关.让我在ARC模式下使用Core Foundation对象作为免费电话.
考虑以下函数(或方法,不确定它是如何调用的):
- (void)saveImageWithData:(NSData*)jpeg andDictionary:(NSDictionary*)dicRef andName:(NSString*)name
{
[self setCapturedImageName:name];
CGImageSourceRef source ;
// Notice here how I use __bridge
source = CGImageSourceCreateWithData((__bridge CFDataRef)jpeg, NULL);
CFStringRef UTI = CGImageSourceGetType(source);
NSMutableData *dest_data = [NSMutableData data];
// And here I use it again
CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data,UTI,1,NULL);
CGImageDestinationAddImageFromSource(destination,source,0, (__bridge CFDictionaryRef) dicRef);
BOOL success = NO;
success = CGImageDestinationFinalize(destination);
if(!success) {
NSLog(@"***Could not create data from image destination ***");
}
// This only saves to the disk
NSArray …Run Code Online (Sandbox Code Playgroud) ios ×8
objective-c ×3
apple-vision ×1
avfoundation ×1
c ×1
c# ×1
fonts ×1
iphone ×1
java ×1
memory-leaks ×1
opencv ×1
servlets ×1
swift ×1
swift3 ×1
templates ×1
xcode ×1
xcode8 ×1