Skip to content

Commit 86b8ea9

Browse files
committed
Remove sudo. Fewer globals. Tidy some lines
1 parent b37630f commit 86b8ea9

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

qCam.q

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
\l arialBold.q
22

33
//Starts the camera
4-
startcamera:{[]
4+
startcamera:{[width;height;pixelformat]
55
//Start the driver which creates /dev/video0
6-
system"sudo modprobe bcm2835-v4l2";
6+
system"modprobe bcm2835-v4l2";
77
//Start the camera
8-
system"sudo v4l2-ctl -v width=",string[width],",height=",string[height],",pixelformat=",string[pixelformat];
8+
system"v4l2-ctl -v width=",string[width],",height=",string[height],",pixelformat=",string[pixelformat];
99
//Return a handle to the named pipe
1010
hopen`:fifo:///dev/video0
1111
};
@@ -21,8 +21,7 @@ snap:{[handle;size]
2121
//Saves a ppm as a P6 encoded RGB image to disk
2222
saveppm:{[filename;pic]
2323
hsym[`$"." sv string filename,`ppm] 1:
24-
string[pic`encoding],"\n",string[pic`width]," ",string[pic`height]," ",string[pic`maxval],
25-
"\n","c"$pic[`data];
24+
string[pic`encoding],"\n",(" " sv string pic`width`height`maxval),"\n","c"$pic[`data];
2625
};
2726

2827
//Converts our image to greyscale
@@ -36,7 +35,7 @@ greyscale:{[pic]
3635
//Saves pgm saves a P5 encoded greyscale image to disk
3736
savepgm:{[filename;pic]
3837
hsym[`$"." sv string filename,`pgm] 1:
39-
string[pic`encoding],"\n",string[pic`width]," ",string[pic`height]," ",string[pic`maxval],"\n",
38+
string[pic`encoding],"\n",(" " sv string pic`width`height`maxval),"\n",
4039
"c"$pic`data;
4140
};
4241

@@ -77,9 +76,8 @@ convolute:{[pic;kernel]
7776
pic[`data]:{[y;kernel;pic]
7877
(raze kernel)$(raze (pic[`data][y+til (count kernel)];
7978
pic[`data][(y+pic[`width])+til (count kernel)];
80-
pic[`data][(y+2*pic[`width])+til (count kernel)]))}
81-
[;kernel;pic] each
82-
til count pic[`data];
79+
pic[`data][(y+2*pic[`width])+til (count kernel)]))
80+
}[;kernel;pic] each til count pic[`data];
8381
pic
8482
};
8583

@@ -97,7 +95,8 @@ drawSingle:{
9795
16 cut @[x;where x=0;:;0N]
9896
};
9997

100-
draw:{raze each flip drawSingle each x
98+
draw:{
99+
raze each flip drawSingle each x
101100
};
102101

103102
makePGM:{

test.q

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ height:480;
55
pixelformat:`RGB3;
66

77
//Start the camera
8-
camera:startcamera[]
8+
camera:startcamera[width;height;pixelformat];
99

1010
//Create the prototype dictionary
11-
colourPic:`encoding`width`height`maxval`data!(`P6;width;height;255;())
11+
colourPic:`encoding`width`height`maxval`data!(`P6;width;height;255;());
1212

1313
//Grab a frame from the camera
1414
colourPic[`data]:snap[camera;3*colourPic[`width]*colourPic[`height]];
@@ -59,4 +59,3 @@ savepgm[`:test/10_overlay] overlay[textPic;greyPic;50;floor %[;2] greyPic[`width
5959
{system"convert ",x," ",(first "." vs x),".jpg"} each string key `:.;
6060

6161
exit 0
62-

0 commit comments

Comments
 (0)