我尝试在Linux中控制鼠标.Xlib似乎有效,但是当我尝试将它与OpenCV一起使用时,它会一直返回:
Resource temporarily unavailable
Run Code Online (Sandbox Code Playgroud)
所以我决定写"/ dev/psaux".代码如下:
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
unsigned char a[5]={0, 0xff, 0, 0x28, 0xff};
int fp = open ("/dev/psaux", O_WRONLY);
if(!fp)printf("open error:%s\n", strerror(errno));
for(int i = 0; i < 10; i++)
printf("write:%d\t\t%s\n", write(fp, a, 5), strerror(errno));
close(fp);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译它:
gcc my_psaux.c -o my_psaux -std=gnu99 -g
Run Code Online (Sandbox Code Playgroud)
跑,得到
$sudo ./my_psaux
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success
write:5 Success …Run Code Online (Sandbox Code Playgroud) 我使用cv.dft来处理图像,然后使用cv.idft将其恢复到此处的教程之后.但是,最终图像具有非常大的灰度值,远远超过255.
我检查代码,发现扩大来自无处.
这是怎么发生的?我可以获得准确的价值吗?
复制代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('test.bmp',0) # change for your own test image
dft = cv2.dft(np.float32(img),flags = cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
f_ishift = np.fft.ifftshift(dft_shift)
img_back = cv2.idft(f_ishift)
img_back = cv2.magnitude(img_back[:,:,0],img_back[:,:,1])
print (img_back.max(), img_back.min()) # too large!!!!
plt.subplot(121),plt.imshow(img, cmap = 'gray')
plt.title('Input Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(img_back, cmap = 'gray')
plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
plt.show()
Run Code Online (Sandbox Code Playgroud)