我正在尝试从 OpenCV 站点运行 python 示例:
http://docs.opencv.org/trunk/d7/d8b/tutorial_py_lucas_kanade.html
import numpy as np
import cv2
cap = cv2.VideoCapture('slow.flv')
# params for ShiTomasi corner detection
feature_params = dict( maxCorners = 100,
qualityLevel = 0.3,
minDistance = 7,
blockSize = 7 )
# Parameters for lucas kanade optical flow
lk_params = dict( winSize = (15,15),
maxLevel = 2,
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))
# Create some random colors
color = np.random.randint(0,255,(100,3))
# Take first frame and find corners in it
ret, old_frame = …Run Code Online (Sandbox Code Playgroud) 在 Android 9 之前,我可以通过使用 root、系统化我的应用程序和使用下一个 USB 类来绕过 android usb 主机权限确认对话框/sf/answers/1076468291/ /sf/answers/1377729461/
但它不适用于最新的 Android 版本 - 9
它抛出 java.lang.NoSuchMethodError: No interface method grantDevicePermission(Landroid/hardware/usb/UsbDevice;I)V in class Landroid/hardware/usb/IUsbManager; or its super classes (declaration of 'android.hardware.usb.IUsbManager' appears in /system/framework/framework.jar)
fun setUsbPermissionRoot(device: UsbDevice) : Boolean {
if (BuildConfig.DEBUG) Log.i(TAG, "trying set permission")
try {
val pm = App.context.packageManager
val ai = pm.getApplicationInfo(App.context.packageName, 0)
ai?.let {
val b = ServiceManager.getService(Context.USB_SERVICE)
val service = IUsbManager.Stub.asInterface(b)
service.grantDevicePermission(device, it.uid)
try {
service.setDevicePackage(device, App.context.packageName, it.uid)
} catch (e: …Run Code Online (Sandbox Code Playgroud) 在我的 ViewModel 中我有
private val _topicsResponse = MutableStateFlow<Result<List<Topic>>>(Result.Initial)
val topicsResponse = _topicsResponse.asStateFlow()
Run Code Online (Sandbox Code Playgroud)
我从服务器获取数据(主题),这就是数据包装在Result<T>类中的原因。它可以是Result.Initial、Result.Loading、Result.Success和Result.Error
在我的主题屏幕的撰写功能中,我有使用 Snackback 显示错误的逻辑
val topicsResponse: Result<List<Topic>> by topicsViewModel.topicsResponse.collectAsState()
Box(modifier = Modifier.fillMaxSize()) {
...
if (topicsResponse is Result.Error) {
Snackbar(
action = {
Button(onClick = { topicsViewModel.loadTopics() }) {
Text(stringResource(id = R.string.retry_text))
}
},
modifier = Modifier
.padding(8.dp)
.align(Alignment.BottomCenter)
) { Text(text = "Test error message") }
}
}
Run Code Online (Sandbox Code Playgroud)
用topicsResponse is Result.Error在这里好不好?
所以我不确定是否应该使用 …
我试图用鼠标左键单击获取链接(可点击元素的 url),下一个方法不适用于所有元素:
function callback(e) {
if (e.button != 0 ) {
return;
}
alert(e.target.href);
}
document.addEventListener('click', callback, true);
Run Code Online (Sandbox Code Playgroud)
例如,对于 Youtube 网站上的某些元素 - 标题或缩略图(所有这些元素都是可点击的,并且它们会导致一些视频/播放列表):
链接地址是undefined
但它是可点击的,并且 Google Chrome 浏览器会显示该元素所指向的链接的预览:
更新
Youtube 网站上的某些 A 标签将其他元素包裹在其中的问题:<a href="..."><span>...<span/><div.......></a>
我尝试了调试模式(检查),选择了一些此类元素进行检查,并<span>在<a>.
附加解决方案:https://jsfiddle.net/z2huqjjh/2/(如果链接(A标签)动态添加到页面,这将是一个很好的解决方案)
从 Android Oreo 8.0 (26 API) 开始,当使用代码启动 Activity 时,如果先前的实例没有被销毁并且仍然存在,它不会创建新的 Activity,但在以前的 Android(例如 Marshmallow、Nougat)上,它总是创建一个新的 Activity任何状况之下。
为什么它的行为因 Android 版本而异?
我想阻止创建新的 Activity 实例,并在单击通知时从 Android 23 (Marshmallow) 开始将现有的 Activity 实例(如果它仍然存在)置于前面。目前仅适用于 Android Oreo (26)
val intent = Intent(this, TestActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val pendingIntentt = PendingIntent.getActivity(
this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT
)
val ... = NotificationCompat.Builder(this, channelId)
...
.setContentIntent(pendingIntent)
Run Code Online (Sandbox Code Playgroud) android android-intent android-notifications android-activity android-pendingintent
MediaMetadataRetriever我尝试与 Kotlin 一起使用use:
MediaMetadataRetriever().apply {
setDataSource(context, uri)
}.use {
...
}
Run Code Online (Sandbox Code Playgroud)
但它在 Android 6 Marshmallow (23 API) 上给了我一个错误:
java.lang.ClassCastException:android.media.MediaMetadataRetriever 无法转换为 java.lang.AutoCloseable
为什么这样?
android kotlin android-6.0-marshmallow android-6.0.1-marshmallow
初始状态看起来像这样 ( animatedOffset = 0f)
我想得到1f反向梯度:
当前代码:
val transition = rememberInfiniteTransition(label = "NavIconGradientAnim")
val animatedOffset by transition.animateFloat(
initialValue = 0f, targetValue = 1f,
label = "NavIconGradientAnimOffset",
animationSpec = infiniteRepeatable(
animation = tween(1500, easing = LinearEasing),
repeatMode = RepeatMode.Reverse
)
)
Image(
painterResource(id = item.icon),
contentDescription = null,
modifier = Modifier.drawWithCache {
onDrawWithContent {
with(drawContext.canvas.nativeCanvas) {
val angle = 45f
val endX = drawContext.size.width
val endY = (endX * kotlin.math.tan(Math.toRadians(angle.toDouble()))).toFloat()
val checkPoint = saveLayer(null, null)
drawContent()
val gradient …Run Code Online (Sandbox Code Playgroud) android android-animation android-jetpack-compose jetpack-compose-animation android-jetpack-compose-animation
我尝试使用下一个解决方案调整包含透明图像的 UIImage 的大小,但它返回没有透明度的图像,而不是该透明区域变为黑色
extension UIImage{
func resizeImageWith(newSize: CGSize) -> UIImage {
let horizontalRatio = newSize.width / size.width
let verticalRatio = newSize.height / size.height
let ratio = max(horizontalRatio, verticalRatio)
let newSize = CGSize(width: size.width * ratio, height: size.height * ratio)
UIGraphicsBeginImageContextWithOptions(newSize, true, 0)
draw(in: CGRect(origin: CGPoint(x: 0, y: 0), size: newSize))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
}
Run Code Online (Sandbox Code Playgroud) 我收到以下错误
error: incompatible types: NonExistentClass cannot be converted to Annotation
@error.NonExistentClass()
Run Code Online (Sandbox Code Playgroud)
在
@Preview("Drawer contents")
@Preview("Drawer contents (dark)", uiMode = UI_MODE_NIGHT_YES)
@Composable
fun PreviewAppDrawer() {
AppTheme {
Surface {
AppDrawer(
currentScreen = Screen.Home,
onTopLevelScreenNavigate = {},
closeDrawer = { }
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
在发布 gradle 构建期间
我该如何修复它?
适用于调试构建
android ×6
android-jetpack-compose-animation ×1
android-usb ×1
ios ×1
javascript ×1
kotlin ×1
opencv ×1
python ×1
root ×1
swift ×1
usb ×1