我试图将图像旋转一定角度然后在窗口中显示.我的想法是旋转,然后在一个新的窗口中显示它,窗口的新宽度和高度从旧的宽度和高度计算:
new_width = x * cos angle + y * sin angle
new_height = y * cos angle + x * sin angle
Run Code Online (Sandbox Code Playgroud)
我期待结果如下所示:

但事实证明结果如下:

我的代码在这里:
#!/usr/bin/env python -tt
#coding:utf-8
import sys
import math
import cv2
import numpy as np
def rotateImage(image, angle):#parameter angle in degrees
if len(image.shape) > 2:#check colorspace
shape = image.shape[:2]
else:
shape = image.shape
image_center = tuple(np.array(shape)/2)#rotation center
radians = math.radians(angle)
x, y = im.shape
print 'x =',x
print 'y =',y
new_x = math.ceil(math.cos(radians)*x + math.sin(radians)*y) …Run Code Online (Sandbox Code Playgroud) 我有这个curry功能:
(define curry
(lambda (f) (lambda (a) (lambda (b) (f a b)))))
Run Code Online (Sandbox Code Playgroud)
我想就是这样(define curry (f a b)).
我的任务是编写一个函数consElem2All使用curry,它应该像
(((consElem2All cons) 'b) '((1) (2 3) (4)))
>((b 1) (b 2 3) (b 4))
Run Code Online (Sandbox Code Playgroud)
我已经定期编写了这个函数:
(define (consElem2All0 x lst)
(map (lambda (elem) (cons x elem)) lst))
Run Code Online (Sandbox Code Playgroud)
但仍然不知道如何改造它curry.谁能帮我?
提前致谢
bearzk
我想计算Scheme中数字的位数总和.它应该像这样工作:
>(sum-of-digits 123)
6
Run Code Online (Sandbox Code Playgroud)
我的想法是将数字转换123为字符串"123",然后将其转换为列表'(1 2 3)然后用于(apply + '(1 2 3))获取6.
但不幸的是,它没有像我想象的那样工作.
>(string->list(number->string 123))
'(#\1 #\2 #\3)
Run Code Online (Sandbox Code Playgroud)
显然'(#\1 #\2 #\3)和'(1 2 3)... 不一样,因为我racket在DrRacket下使用语言,所以我不能使用像char->digit.
谁能帮我解决这个问题?