duangsuse::Echo
715 subscribers
4.25K photos
127 videos
583 files
6.46K links
import this:
美而不丑、明而不暗、短而不凡、长而不乱,扁平不宽,读而后码,行之天下,勿托地上天国。
异常勿吞,难过勿过,叹一真理。效率是很重要,盲目最是低效。
简明是可靠的先验,不是可靠的祭品。
知其变,守其恒,为天下式;穷其变,知不穷,得地上势。知变守恒却穷变知新,我认真理,我不认真。

技术相干订阅~
另外有 throws 闲杂频道 @dsuset
转载频道 @dsusep
极小可能会有批评zf的消息 如有不适可退出
suse小站(面向运气编程): https://WOJS.org/#/
Download Telegram
duangsuse::Echo
#Cplusplus #CV 🤔 讲真,我真的不喜欢 OpenCV 的动态属性,它把本来可以轻易自动补齐的东西变成了还要查会文档、本来可以更强类型的东西做成了一堆 int 不仅使用动态属性,还不对常见 prop (比如 fps, position) 做些辅助属性…… In [1]: from cv2 import CAP_PROP_POS_MSEC CAP_PROP_POS_AVI_RATIO CAP_PROP_POS_FRAMES CAP_PROP_POS_MSEC OpenCV…
之前记下的 API 都是什么情况…… 要完成这些,我必须得到按 行/字 迭代每帧像素的方法
https://docs.opencv.org/4.5.0/d8/dfe/classcv_1_1VideoCapture.html 找到官方文档了(话说一般 CV 都是 #Python 写应用……
https://docs.opencv.org/4.5.0/d3/d63/classcv_1_1Mat.html 还有这个,单帧图像接口

看了半天找到 opencv2/videoio.hpp, highgui/highgui.hpp 和 imread/imwrite, empty, cvNamedWindow,waitKey, CV_WINDOW_AUTOSIZE, imshow, VideoCapture, read, operator>>, Mat ,channels, at, Scalar,uchar,Vec3b,val[] 这样的符号 #cplusplus #api #doc 🤔
Mat img(/*.rows*/1920, /*.cols*/1080, CV_8UC3);
typedef cv::Point3_<uint8_t> Pixel;
for (int i=0; i<img.rows; i++) { // raw access
Pixel *p = image.ptr<Pixel>(i, 0), *p1 = p + image.cols;
for (; p!=p1; p++) { *p.x = 255; }
}
for (Pixel &p : cv::Mat_<Pixel>(img)) { p.x = 255; } // mat iter
img.forEach<Pixel>([](Pixel &pixel, const int* position) { p.x = 255; }); // parallel forEach
//C++11 lambda, old:
struct Operator { operator()/*^above*/ }
好了,找到了 Video 的 nextImage 和 Image 的 n[row/col], pixelAt 操作我就可以写了……

相关链接:
[Linux Terminal has the capability of displaying 8-bit colour, so why not play something on it?](https://gist.github.com/Trumeet/fd4e93d69d78dc4ac14d5cac42dfff7e)
[OpenCV - Colored Images to GrayScale - Tutorialspoint](https://www.tutorialspoint.com/opencv/opencv_colored_images_to_grayscale.htm)
[OpenCV: cv::VideoCapture Class Reference](https://docs.opencv.org/4.5.0/d8/dfe/classcv_1_1VideoCapture.html)
[Tutorial 6 - Assessing the pixel values of an image OpenCv C++ | ProgTpoint](https://progtpoint.blogspot.com/2017/02/tutorial-6-assessing-pixel-values-of.html)
[duangsuse-valid-projects/Essay-DIP-BMP-SIMD-Operation: C11 BMP Image Reading / Writing, SIMD using GCC xmminstric.h operations like AND / XOR / Dense](https://github.com/duangsuse-valid-projects/Essay-DIP-BMP-SIMD-Operation#my-machine)
[duangsuse-valid-projects/Essay-CSharp-DIP.Performance.Parallel: 🐔 versus 👨🏻‍🎓: WHO is faster? Is CSharp &quot;slow&quot;?](https://github.com/duangsuse-valid-projects/Essay-CSharp-DIP.Performance.Parallel/)
asciiv.cpp
2.1 KB
#cplusplus #code #linux #cli #cv #cg 支持自动缩放(cv::resize),不过看以前写的自动缩小也简单,算下 1 pixel 代表原img 的 pix step ,average 就可以了 (就这我居然还开了个非gist项目...)
Screenshot_20210116_153204.png
283.5 KB
./a.out '[file]'
Geo: [379 x 104]
[ INFO:0] VIDEOIO: Enabled backends(6, sorted by priority): GSTREAMER(1000); V4L2(990); OPENNI(980); CV_IMAGES(970); CV_MJPEG(960); FIREWIRE(950)
[ INFO:0] OpenCV | GStreamer: /home/DuangSUSE/下载/Telegram Desktop/video_2021-01-16_14-23-05.mp4
[ INFO:0] OpenCV | GStreamer: mode - FILE
[ WARN:0] OpenCV | GStreamer warning: unable to query duration of stream
[ WARN:0] OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
mvn.py
1.1 KB
#Python #tools #cli #code #Java #Maven from lxml import builder, etree
def gavTo(e, g,a,v): [e.append(builder.E(t, s)) for t,s in {"groupId":g, "artifactId":a, "version":v}]
root = builder.E("project", builder.E("modelVersion", "4.0.0"))
root.append(builder.E("build", listE("plugin", gavTo, [("org.apache.maven.plugins", "maven-compiler-plugin", "3.1")] ) ))
root.append(listE("dependency", gavTo, [f"org.jcodec:{s}:0.2.3" for s in "jcodec", "jcodec-javase"]))
gavTo(root, "trumeet","asciiart","1.0-SNAPSHOT")
print(etree.tostring(root))
...https://paste.ubuntu.com/p/K29vXcjY87/
开发过程中处理 org.jcodec:-,--javase:0.2.3 这种转换时我咧嘴了——在 gavTo 发现要展开简写时,listE 无法提供重新 add 的方法,因为它是面向 ops.forEach { it(data) } 的映射!
为了解决这个问题,我尝试用函数式 cps (编程风格,就是不 return 而带 callback)结果发现很难提供——首先 callsite 也必须提供 [op() for ...] 的上下文,Py 里这个改动是侵入式的,不能隐式传参,其次那必须要 def 里另起一行
后来提出先 gavSplitflatten (Py 不能 flatMap 但有对 map(f,xs) 参数的 starmap... 兼容不到我这面),包括结构的类型都很完美。
duangsuse::Echo
mvn.py
Screenshot_20210116_172723.png
39.7 KB
mvn.py trumeet:asciiart:1.0-SNAPSHOT org.jcodec:-,--javase:0.2.3|diff pom.xml -
最讨厌冗余代码了,辣鸡数据结构不该手写
duangsuse::Echo
mvn.py
刚才说完这个我突然想到关于这个 CPS(continuation-passing-style) 的一点不对…… #functional
看起来要么然之前在那篇文章上看的说法是错的,要么然 CPS 是一个类 longjmp() 的控制流概念,不是函数式概念

刚才说的 listE("item", ) = <items>$=<item> op($)</items> 是这样定义的(#Python 的压行技巧,不过之前说的 walrud operator 发现根本不能用):
def listE(tag, op, xs): e = E(tag+"s" if tag[-1]!='y' else tag[:-1]+"ies"); [lets(E(tag), lambda ee: op(ee,x), e.append) for x in xs]; return e

如果
lets(E(tag), lambda ee: op(ee,x), e.append)
是 cps call-site ,那交给 callee 调用前的 continuation 应该是从 lets() 的头部(?)
程序可组合性的关键点在于,op “返回”后要能覆盖 x 才能算够用,但此例 op 也得能覆盖(而且要实现仅改 gavTo(e,coord) 的“单至多项展开”,这还远远不够吧)
如果不知道 return-side 的 type (接收什么变量),就是说这种 cps 式编程,必须显式定义回转方类型,或类型不安全(形式参数列表意义--)
看来只有 yield/resume continuation 是好的(

不对啊, CPS 哪里来的 forEach 😂?看来我还不够了解真正纯的函数式……
pom.xml
934 B
目标是生成一个兼容这个的POM文件(别喷为什么不用Gradle,我只管理依赖懒得被开daemon),16 行感觉还是太多了(吐嘈:结果文件是30行+啊),我本来是想复制粘贴两三行代码就可以创建项目的(虽然不知意义何在),看来还是 LiteratePy 的 way 正确一些,尽量少些模板化“代码”,共用一个项目生成工具是必须的(
root = proj(argv[1], argv[2:])
$mvn.py trumeet:asciiart:1.0-SNAPSHOT org.jcodec:-,--javase:0.2.3>pom.xml

感觉自己的编程习惯就有一点好,非常重视可配置性(当然不会像某些J2EE程序员一样弱智到随地XML),只有重视代码复用才能看到代码的许多其它用途和价值。其实可能只是习惯性提取出几个参数,再加上几个本来能省去的参数而已,整个程序员的走向却会大有不同…… 🤔
This media is not supported in your browser
VIEW IN TELEGRAM
Screenshot_20210116_201051.png
122.9 KB
#Java #plt #types 泛型数组问题真多…… 首先是 Integer[] 和 int[] 不能 autobox 装拆箱(误,这个其实不是拆不拆的问题了,但是 Arrays 居然没提供复制 API...),我写 rangeSwitch(int[],int[]) 它报错 Object,int 没有顶类型(共同超类)... ;因为 Object os/*可*/=(String[])ss; 的默认协变T数组再加上 reified 假泛型问题,必须得用这种方法建立泛型数组,气死我了。
Screenshot_20210116_212315.png
219 KB
#Java 为什么啊…… 比 Yuuta 还多一行,而且看起来贼乱,明明我有很认真做简化功课了的说……
This media is not supported in your browser
VIEW IN TELEGRAM
不知道为什么,我觉得自己代码质量挺好的啊…… 可是看起来就过于紧凑
明明很有自信的说,看来要重构了……
This media is not supported in your browser
VIEW IN TELEGRAM
有的时候真的羡慕 Yuuta 那样的开发者,即便是很麻烦的工作,也能用很简单短篇的代码实现,哪怕会有一大堆类似的行居然也会比我的短
像我要省行数,总是在可读性或算法与面向对象模式上极限1换1……

是应该改一下套路,之前习惯的是有语义区别可以不换行不空格,究竟是 Java 该换的肯定要换,不换的话没有眼力看啦……
for (String fp : args) u.tryRun(() -> play(new File(fp)), fp); 🌚 我脑子瓦特了写了这么个函数(() -> 内仍需 checked exception...)
方法引用中抛出的类型java.io.IOException不兼容 啊啊啊啊啊 🌝我就不该觉得 Java 会不检查,比民政局管得宽……
世 界 级 检 查
满 贯 类 型 安 全
duangsuse::Echo
for (String fp : args) u.tryRun(() -> play(new File(fp)), fp); 🌚 我脑子瓦特了写了这么个函数(() -> 内仍需 checked exception...) 方法引用中抛出的类型java.io.IOException不兼容 啊啊啊啊啊 🌝我就不该觉得 Java 会不检查,比民政局管得宽…… 世 界 级 检 查 满 贯 类 型 安 全
LINES=68,COLUMNS=236 mvn exec:java -Dexec.mainClass=JPlayer1 -Dexec.args=a.mp4
LINES=68,COLUMNS=236 mvn exec:java -Dexec.mainClass=JPlayer -Dexec.args='a_con.mp4 a.mp4.wav'

真棒, Yuuta 的一直可以运行,我的老出问题 🌝