小编Sou*_*jit的帖子

从IPLImage到Mat

我很熟悉OpenCV 1.1中使用的IPL图像格式.但是我使用的是最新的2.4版本,并希望切换到OpenCV的C++界面.这是我访问图像中像素的方法:

int step = img->widthStep;
int height = img->height;
int width = img->width;
unsigned char* data = (unsigned char*) img->imageData;

for (int i=0; i<height; i++)
{
    for (int j=0; j<step; j+=3)          // 3 is the number of channels.
    {
        if (data[i*step + j] > 200)      // For blue
            data[i*step + j] = 255;

        if (data[i*step + j + 1] > 200)  // For green
            data[i*step + j + 1] = 255;

        if (data[i*step + j + 2] > 200) …
Run Code Online (Sandbox Code Playgroud)

opencv image-processing iplimage

6
推荐指数
1
解决办法
1232
查看次数

正则表达式匹配python中方括号中的数字

我需要匹配并返回方括号中包含的数字的字符串索引.示例字符串:

Gabrilovich和Markovitch [11,12]提出了一种使用条件随机场[6]作为训练过程的方法.....

在这里,我想使用正则表达式在上述情况下提取任何给定数字的索引,如11,12或6.我在尝试

pattern = re.compile(r'[/11/]') # for 11
result =  re.search(pattern, text, flags=0)
print result.start()
Run Code Online (Sandbox Code Playgroud)

然而,有了这个,我没有得到理想的结果.注意:我需要一个解决方案来匹配我想要的确切数字,而不是括号内的任何给定数字.

python regex text

3
推荐指数
1
解决办法
1569
查看次数

使用 CoreImage 裁剪出脸部

我需要从给定图像中裁剪出一张/多个面孔,并将裁剪后的脸部图像用于其他用途。我正在使用 CoreImage 中的 CIDetectorTypeFace。问题是仅包含检测到的脸部的新 UIImage 需要更大的尺寸,因为头发被剪掉或下颌被剪掉。initWithFrame:faceFeature.bounds我如何增加??的大小?我正在使用的示例代码:

    CIImage* image = [CIImage imageWithCGImage:staticBG.image.CGImage];
    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                          context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
    NSArray* features = [detector featuresInImage:image];

    for(CIFaceFeature* faceFeature in features)
    {
       UIView* faceView = [[UIView alloc] initWithFrame:faceFeature.bounds];
       faceView.layer.borderWidth = 1;
       faceView.layer.borderColor = [[UIColor redColor] CGColor];
       [staticBG addSubview:faceView];

       // cropping the face
       CGImageRef imageRef = CGImageCreateWithImageInRect([staticBG.image CGImage], faceFeature.bounds);
       [resultView setImage:[UIImage imageWithCGImage:imageRef]];
       CGImageRelease(imageRef);
    }
Run Code Online (Sandbox Code Playgroud)

注意:我用来显示检测到的面部区域的红框与裁剪后的图像根本不匹配。也许我没有正确显示框架,但由于我不需要显示框架,我真的需要裁剪掉的脸,我不太担心它。

crop objective-c core-image face-detection

1
推荐指数
1
解决办法
2376
查看次数

结构数组 - C中的内存释放

我正在尝试使用静态数组实现基于二进制堆的优先级队列(我稍后将使用链表,只是想先用数组进行测试).

typedef struct n
{
    int x;
    int y;
    int size;
    double value;
} node;

node arr[100];
int total = 1;

void insertElement(int x, int y, int size, double value)
{
    node n;
    n.x     = x;
    n.y     = y;
    n.size  = size;
    n.value = value;

    arr[total] = n;

    if (total > 1)
        insertArrange(total);

    total += 1;
}
Run Code Online (Sandbox Code Playgroud)

现在在删除功能中,我将返回最顶层节点并将其删除,然后重新排列整个堆.问题是我无法释放任何记忆.假设我使用

free(&arr[1]);
Run Code Online (Sandbox Code Playgroud)

我得到指针被释放没有分配错误.这是正确的实施方式吗?如何解决内存问题?

我正在使用Xcode和Apple LLVM 4.2编译器.这整个事情最终将被放入Objective-C中的一个更大的项目中,但是现在我不想使用NSMutableArray.我想要一个简单的C解决方案.

c struct memory-management priority-queue data-structures

1
推荐指数
1
解决办法
376
查看次数