TypeError:使用基本操作时,只能将length-1数组转换为Python标量

时间:2015-06-13 02:00:15

标签: python opencv

我试着编写代码:

//This is an action connected to the button which will present the ActionController
- (IBAction)addFriend:(id)sender {



    view =   [UIAlertController alertControllerWithTitle:@"Add Friend" message:@"Write the friend to add"preferredStyle:UIAlertControllerStyleAlert];

    [view addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"Friend";
        textField.delegate = self;
        textField.tag = 01;
    }];

    [self presentViewController:view animated:YES completion:nil];

}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    if(textField.tag == 01){

        [array insertObject:textField.text  atIndex:array.count];
        [view dismissViewControllerAnimated:YES completion:^{
            [self.pickerView reloadAllComponents];
        }];

        return YES;

    }

    return YES;

}

显示错误:

import numpy as np
import cv2

def duplicate(im):
    img1 = im.copy()
    k = im.shape
    i=1
    x=k[0]
    y=k[1]
    while(i<(x-2)):
        j=1
        while(j<(y-2)):
            print i,j
            a = (int(im[i,j+1])-int(im[i,j]))
            b = (int(im[i+1,j])-int(im[i,j]))
            c = (a**2) + (b**2)
            c = np.sqrt(c)
            if(c>=40):
                img1[i,j] = img1[i-1,j] = img1[i,j-1] = img1[i-1,j-1] = 255
            else:
                img1[i,j] = 0
            j+=1
        i+=1
    return img1
im = cv2.imread('book013.png')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
#ret,thresh = cv2.threshold(imgray,50,255,0)
img1 = duplicate(im)
image, contours, hierarchy = cv2.findContours(img1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#print contours[42]
l=len(contours)
i=0
rect = cv2.minAreaRect(contours[l-1])
box = cv2.boxPoints(rect)
box = np.int0(box)
image1 = cv2.drawContours(im,[box],0,(0,0,255),2)
while(i<l):
    print contours[i]
    print cv2.contourArea(contours[i])
    i+=1
#area = cv2.contourArea(contours)
#print area
#cv2.imwrite('bookd013.png',image)
cv2.imshow('image',image1)
#cv2.imshow('image'image)
cv2.waitKey(0)
cv2.destroyAllWindows()

有人可以建议对此代码进行哪些更改?

0 个答案:

没有答案