我想将字符串中的一部分移到字符串的开头。请参见下面的示例。可以使用正则表达式来完成吗?
在:
image = cv2.imread('image.jpg',cv2.IMREAD_UNCHANGED)
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
ret, corners=cv2.findCirclesGrid(gray,(5,5),None)
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001)
corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
((x,y),(w,h),angle) = cv2.minAreaRect(corners2)
rows,cols = image.shape[:2]
angle += 90
M = cv2.getRotationMatrix2D((int(cols/2),int(rows/2)), angle, 1.0)
nimg = cv2.warpAffine(image,M,(cols,rows))
退出:
c("41_exo","47_exo","48_exo")
答案 0 :(得分:2)
答案 1 :(得分:0)
或没有正则表达式:
sapply(
strsplit(vec, "_"),
function(x) {
paste0(toupper(substring(x[2], 1, 1)), substring(x[2], 2), "_", x[1])
}
)
[1] "Exo_41" "Exo_47" "Exo_48"