小编Chr*_*nam的帖子

如何规范化卷积图像?我是不是该?

我试图用卷积进行边缘检测.我想我需要在卷积后对图像进行标准化.

我正在使用此处指定的卷积矩阵:https: //en.wikipedia.org/wiki/Kernel_(image_processing)#Convolution

附件是一些r代码,源和输出图像......

require(jpeg)
myjpg <- readJPEG("mtg.jpg")

grayImg <- myjpg[,,1]+myjpg[,,2]+myjpg[,,3] # reduce to gray
grayImg <- grayImg/max(grayImg) # normalize
dim(grayImg)


convolve <- function(img, f){
    newimg <- img
    radius <- as.integer(nrow(f)/2)+1
    print(radius)
    for(i in c(1:nrow(img))){
        for(j in c(1:ncol(img))){
            f_sub <- f[c(max(1,radius-i+1):min(nrow(f),nrow(img)-i+radius)),c(max(1,radius-j+1):min(ncol(f),ncol(img)-j+radius))]
            img_sub <- img[c(max(1,i-radius+1):min(nrow(img),i+radius-1)),c(max(1,j-radius+1):min(ncol(img),j+radius-1))]
            wavg <- sum(as.vector(f_sub)*as.vector(img_sub))# / sum(as.vector(f_sub)) # todo, not sure about this division
            newimg[i,j] <- wavg
        }
    }
    return(newimg)
}

edgeFilter <- matrix(c(-1,-1,-1,-1,8,-1,-1,-1,-1), ncol = 3)

outimg <- convolve(grayImg,edgeFilter)

outimg <- outimg - min(outimg)
outimg …
Run Code Online (Sandbox Code Playgroud)

r image-processing

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

画一个半圆形按钮iOS

我正在尝试绘制一个半圆形按钮.我在绘制半圆并将其附加到我在xcode中制作的按钮时遇到了麻烦.xcode中的按钮具有约束,将其固定到屏幕底部并使其居中.我在视图控制器中引用该按钮,然后尝试将其覆盖为半圆,如下所示.我得到一个空白按钮.我还在按钮所在的故事板的坐标中进行了硬编码.有没有更好的方法呢?

let circlePath = UIBezierPath.init(arcCenter: CGPoint(x: 113.0, y: 434.0),
radius: 10.0, startAngle: 0.0, endAngle: CGFloat(M_PI), clockwise: true)

let circleShape = CAShapeLayer()
circleShape.path = circlePath.CGPath

sunButton.layer.mask = circleShape
Run Code Online (Sandbox Code Playgroud)

ios swift

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

NSDictionary allKeys和allValues订单更改

我有一个视图控制器,它有一个表视图,并且,对于该表视图的数据源,我使用NSDictionary包含两个键和两个值的视图.我用对象文字初始化字典,我也有一个NSArray包含应该与字典中的值对应的值的字典.

NSDictionary *dict = @{@"Key1" : @"Value1", @"Key2" : @"Value2"};
NSArray *arr = @[@"Value for Key 1", @"Value for Key 2"];
Run Code Online (Sandbox Code Playgroud)

在我的表视图中cellForRowAtIndexPath:,我有以下内容

static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];

cell.textLabel.text = dict.allKeys[indexPath.row];
cell.imageView.image = dict.allValues[indexPath.row];
cell.textLabel.numberOfLines = 0;

return cell;
Run Code Online (Sandbox Code Playgroud)

但是,无论我初始化的顺序dict(可能是@{@"Key2" : @"Value2", @"Key1" : @"Value1"}),值2总是先行.当我向字典中添加更多对象时,这会导致问题,因为索引arr必须与索引匹配dict,这个问题也使得表视图的显示方式与我想要的方式不同.有谁知道这里出了什么问题?

为了帮助可视化问题,这里有一个图表来演示

NSDictionary *dict = @{@"Key1" : @"Value1", @"Key2" : …
Run Code Online (Sandbox Code Playgroud)

objective-c nsdictionary ios

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

C++ - 使用相同的函数从文件或内存缓冲区中读取

是否有一个标准的C/C++函数,它接受文件句柄/指针或指向内存缓冲区的指针,并从文件/缓冲区中读取数据?

我有一个函数从文件中提取数据,对所述数据执行操作,并通过套接字发送出去.我还有一个函数,它以char缓冲区的形式获取数据,对该数据执行完全相同的操作,并通过套接字发送它.这个问题并不难.我只是觉得如果有像这样的功能会很方便

read(void *dest, void *src, int src_type, size_t amount)
Run Code Online (Sandbox Code Playgroud)

c c++

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

应用程序关闭后,C char不保存到文件

我正在制作交流功能并将其与mac app一起用于测试和学习目的.当我尝试使用以下方法将文本打印到文件时:

FILE *f = fopen("text.txt", "w+");
fflush(f);
if (f==NULL) {
    f = fopen("text.txt", "w+");
    saveToFile(text);
    printf("null\n");
    return 0;
}
else{
    int i = fprintf(f, "%s", text);
    if (i>0) {
        return  1;
    }
    else{
        return 0;
    }
}
fclose(f);
Run Code Online (Sandbox Code Playgroud)

它将它打印到文件,但只有在我退出应用程序后.任何人都知道为什么会发生这种情况?

c printf file

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

C#命令没有写一行

嗯,您好,我如何让这个控制台写一行?我设法使它在处理时运行cmd.exe,但它没有写入行.

private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == "alpha")
        {
            progressBar1.Value = 100;
            if (progressBar1.Value == 100)
            {
                MessageBox.Show("Welcome back master!");
                System.Diagnostics.Process.Start(@"C:\Windows\System32\cmd.exe");
                Console.WriteLine("Hello!!!");
            }

        }
Run Code Online (Sandbox Code Playgroud)

c#

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

char []到uint32_t无法正常工作

我使用以下内容将a转换char[4]为a uint32_t.

frameSize = (uint32_t)(frameSizeBytes[0] << 24) | (frameSizeBytes[1] << 16) | (frameSizeBytes[2] << 8) | frameSizeBytes[3];
Run Code Online (Sandbox Code Playgroud)

frameSize是一个uint32_t变量,frameSizeBytes是一个char[4]数组.例如,当数组包含以下值时(以十六进制表示)

00 00 02 7b
Run Code Online (Sandbox Code Playgroud)

frameSize设置为635,这是正确的值.此方法也适用于其他字节组合,但以下情况除外

00 00 9e ba
Run Code Online (Sandbox Code Playgroud)

对于这种情况,frameSize设置为4294967226,根据本网站,这是不正确的,因为它应该是40634.为什么会发生这种情况?

c byte

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

ImagePicker关闭tabBar Nav Controller

我有一个Tab Bar Controller,它提供了一个NavigationController.在其中一个ViewControllers中,我推动了这一点,我添加了imagePickerController来选择一张照片.当我取消或选择图片时,标签栏消失...我试图寻找答案,但我找不到引用我的具体问题的答案.

这是我的图像选择器方法

    @IBAction func attachImageBtnTapped(sender: AnyObject) {
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){
            imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
            imagePicker.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
            self.presentViewController(imagePicker, animated: true, completion: nil)
        }
    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        attachImageBtn.backgroundColor = UIColor.greenColor()
        dismissViewControllerAnimated(true, completion: nil)
    }
Run Code Online (Sandbox Code Playgroud)

我怎么能避免这个?我试着看看我是否将tabar设置为隐藏在viewWillAppear之类的地方但是号码.

任何想法,任何帮助将非常感谢!

ios swift

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

为什么我的UITableView没有完全加载单元格内容?

似乎我的表部分加载,其余的加载在我上下滚动几次之后.毫无疑问,这与我[[self myTableView] reloadData];和我之间的位置有关,-(void)viewWillAppear:(BOOL)animated,-(void)viewDidAppear:(BOOL)animated,-(void)viewDidLoad虽然我不能把手指放在上面.在这种情况下,没有要求提供数据; 我只是尝试在应用启动时立即加载所有指定的数据.

#import "PreViewController.h"
#import <CoreData/CoreData.h>
#import <CoreLocation/CoreLocation.h>
#import "FlipsideViewController.h"
#import "AppDelegate.h"
#import <SystemConfiguration/SystemConfiguration.h>
#import "Reachability.h"

@interface PreViewController ()

{
    NSMutableArray *arrayNo;
}

@end

@implementation PreViewController

-(void)viewWillAppear:(BOOL)animated
{
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkForReachability) name:kReachabilityChangedNotification object:nil];

    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];

    NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

    if(remoteHostStatus == NotReachable)
    {
        UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle: @"Please check your network connection and try again."
                          message: @""
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
        [alert show];
    }
 } …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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

C反向功能不适用于32个字符

为了测试我的技能,我正在尝试编写自己的几个标准库函数版本.我写了一个替代strlen(),strlength():

int strlength(const char *c){
    int len = 0;
    while (*c != '\0') {
        c++;
        len++;
    }
    return len;
}
Run Code Online (Sandbox Code Playgroud)

其中包括null-terminator,我正在尝试编写一个函数来反转字符串.这个:

char *reverse(const char *s){
    char *str = (char *)malloc(sizeof(char) * strlength(s));
    int i = 0;
    while (i < strlength(s)) {
        str[i] = s[(strlength(s) - 1) - i];
        i++;
    }
    str[strlength(s)] = '\0';
    return str;
}
Run Code Online (Sandbox Code Playgroud)

适用于每个字符串,除了一个包含32个字符(不包括null-terminator)之类的字符串foofoofoofoofoofoofoofoofoofoofo.它挂在reverse()函数while循环中.对于所有其他数量的字符,它的工作原理.为什么会这样?

c string while-loop

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

标签 统计

c ×4

ios ×4

objective-c ×2

swift ×2

byte ×1

c# ×1

c++ ×1

file ×1

image-processing ×1

nsdictionary ×1

printf ×1

r ×1

string ×1

uitableview ×1

while-loop ×1