added code onto GIT

main
Charles 8 years ago
parent 5670f4cc14
commit a527398f5a
  1. 205
      1
  2. BIN
      Eiffel_Tower_01.jpg
  3. BIN
      Nelson-Mandela1.jpg
  4. 48
      README
  5. BIN
      astro_test_image.jpg
  6. 164
      gen_psf_interferometer_detect_skyim.py
  7. 216
      gen_psf_interferometer_detect_skyimCJC.py
  8. BIN
      test.jpg
  9. 62
      testFrameReduce.py
  10. 22
      testVLBIImage.py

205
1

@ -0,0 +1,205 @@
#! /usr/bin/python
"""
Interferometer/PSF simulator
Created by: Jack Hickish
Minor Modifications by: Griffin Foster
Added threshold detection option to allow non-circular layouts (i.e. handdrawn) Charles Copley
TODO: add color
TODO: adjust detection paramters
TODO: add freeze/unfreeze command
TODO: add rotation command
"""
import cv2 #for ubuntu 12.04 install see: http://karytech.blogspot.com/2012/05/opencv-24-on-ubuntu-1204.html
import cv
import numpy as np
import time
import sys, optparse
import pdb
import matplotlib.pylab as plt
def cvfast_conv(image,psf):
max_size = np.array([np.max([image.shape[0],psf.shape[0]]),np.max([image.shape[1],psf.shape[1]])])
n = cv.GetOptimalDFTSize(max_size[0]*2)
m = cv.GetOptimalDFTSize(max_size[1]*2)
imagePad=np.zeros((n,m))
imagePad[:image.shape[0],:image.shape[1]]=image
imageDirty=np.fft.irfft2(np.fft.rfft2(imagePad) * np.fft.rfft2(psf, imagePad.shape))
print image.shape, psf.shape, n,m
return imageDirty[psf.shape[0]/2:image.shape[0]+psf.shape[0]/2,psf.shape[1]/2:image.shape[1]+psf.shape[1]/2]
#return imagePad
def cv2array(im):
depth2dtype = {
cv.IPL_DEPTH_8U: 'uint8',
cv.IPL_DEPTH_8S: 'int8',
cv.IPL_DEPTH_16U: 'uint16',
cv.IPL_DEPTH_16S: 'int16',
cv.IPL_DEPTH_32S: 'int32',
cv.IPL_DEPTH_32F: 'float32',
cv.IPL_DEPTH_64F: 'float64',
}
arrdtype=im.depth
a = np.fromstring(
im.tostring(),
dtype=depth2dtype[im.depth],
count=im.width*im.height*im.nChannels)
a.shape = (im.height,im.width,im.nChannels)
return a
def edgeDetect(image):
##function that uses edge detection thresholding to find the locations of the points
pdb.set_trace()
image=~image ##we need to invert so that the points are turned white.
thresh1 = cv2.Canny(image,70,255) ##first set up the thresholding
contours, hierarchy = cv2.findContours(thresh1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
pos=[]
for cnt in range(len(contours)):
peri = cv2.arcLength(contours[cnt], True)
approx = cv2.approxPolyDP(contours[cnt], 0.02 * peri, True)
# cv2.drawContours(thresh1, [approx], -1, (255, 255, 0), 6)
M=cv2.moments(contours[cnt])
try:
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
cv2.circle(image,(cx,cy),10,(255,255,0),5)
pdb.set_trace()
pos.append([cx,cy])
except:
print 'error'
try:
print cnt,cx,cy
except:
print 'error'
cv2.imshow("image",image)
cv2.waitKey(0)
return pos
def array2cv(a):
dtype2depth = {
'uint8': cv.IPL_DEPTH_8U,
'int8': cv.IPL_DEPTH_8S,
'uint16': cv.IPL_DEPTH_16U,
'int16': cv.IPL_DEPTH_16S,
'int32': cv.IPL_DEPTH_32S,
'float32': cv.IPL_DEPTH_32F,
'float64': cv.IPL_DEPTH_64F,
}
try:
nChannels = a.shape[2]
except:
nChannels = 1
cv_im = cv.CreateImageHeader((a.shape[1],a.shape[0]),
dtype2depth[str(a.dtype)], nChannels)
cv.SetData(cv_im, a.tostring(),a.dtype.itemsize*nChannels*a.shape[1])
return cv_im
o = optparse.OptionParser()
o.set_usage('%prog [options]')
o.set_description(__doc__)
o.add_option('-i','--input',dest='input', default=None,
help='Input \'sky\' image, Default: HARDCODED')
o.add_option('-c','--camera',dest='camera', default=1, type='int',
help='Camera device ID in /dev/video*, Default: 1')
o.add_option('-r','--res',dest='res', default=4, type='int',
help='Resolution factor, increase this value to decrease the resolution, Default: 4')
opts, args = o.parse_args(sys.argv[1:])
CAMERA_DEVICE_INDEX=opts.camera #check /dev/, ID is attached to video device (0 is in the internal)
#cv.NamedWindow("Antenna Layout", cv.CV_WINDOW_AUTOSIZE)
#cv.NamedWindow("Target Image", cv.CV_WINDOW_AUTOSIZE)
#cv.NamedWindow("Point Spread", cv.CV_WINDOW_AUTOSIZE)
#cv.NamedWindow("Observed Image", cv.CV_WINDOW_AUTOSIZE)
#cam0 = cv.CaptureFromCAM(CAMERA_DEVICE_INDEX)
if opts.input is None:
target_image = cv2.imread('/home/griffin/Downloads/interactiveInterferometer/astro_test_image.jpg')
else:
target_image=cv2.imread(opts.input)
target_img_grey = cv2.cvtColor(target_image,cv2.cv.CV_BGR2GRAY)
target_img_lying = target_img_grey.copy()
#saturated image
target_img_grey[target_img_grey>100] = 255
target_img_grey[target_img_grey<255] = 0
RESCALE_FACTOR=opts.res #decrease to change the effective resolution
ysize=480
xsize=640
#make a 2D Gaussian to modulate the PSF with
def gauss2d(x0,y0,amp,stdx,stdy):
return lambda x,y: amp*np.exp(-1.*( (((x-x0)**2.)/(2*stdx**2.)) + (((y-y0)**2.)/(2*stdy**2.)) ))
gaussFunc=gauss2d(0.,0.,1.,30.,30.)
xx = np.arange(xsize)-(xsize/2)
yy = np.arange(ysize)-(ysize/2)
xv, yv = np.meshgrid(xx, yy)
gaussGrid=gaussFunc(xv,yv)
while(True):
pdb.set_trace()
cam0t=cv2.VideoCapture(CAMERA_DEVICE_INDEX)
ret,frame = cam0t.read()
layout_img=frame
#ayout_img = cv.QueryFrame(cam0)
# layout_img_grey = cv.CreateImage((layout_img.width,layout_img.height),layout_img.depth,1)
# cv.CvtColor(layout_img,layout_img_grey,cv.CV_BGR2GRAY)
#ayout_img_grey_arr = cv2array(layout_img_grey)
layout_img_grey_arr = cv2.cvtColor(layout_img,cv2.COLOR_BGR2GRAY)
station_locs = np.zeros([ysize/RESCALE_FACTOR,xsize/RESCALE_FACTOR])
#cv2.HoughCircles(image, method, dp, minDist, circles, param1, param2, minRadius, maxRadius)
# image: input webcam image size
# method: only cv.CV_HOUGH_GRADIENT exists
# dp: Inverse ratio of the accumulator resolution to the image resolution. this basically affects the min/max radius
# minDist: Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
# circles: set to None
# param1: threshold parameter
# param2: The smaller it is, the more false circles may be detected.
# minRadius: Minimum circle radius
# maxRadius: Maximum circle radius
# circles = cv2.HoughCircles(layout_img_grey_arr, cv.CV_HOUGH_GRADIENT,2,10,None,100,35,5,30)
pdb.set_trace()
targets=edgeDetect(layout_img_grey_arr)
circles=np.array(targets)
if circles is not None:
pdb.set_trace()
for cn,circle in enumerate(circles[0]):
pdb.set_trace()
x,y = circle[1],circle[0]
print "we have circle at %d,%d"%(x,y)
try:
layout_img_grey_arr[x-5:x+5,y-5:y+5]=255
except:
pass
station_locs[x/RESCALE_FACTOR,y/RESCALE_FACTOR]=1
psf = np.fft.fftshift(np.abs(np.fft.fft2(station_locs,s=[ysize,xsize]))**2)
#psf=psf[(ysize/2)-64:(ysize/2)+64,(xsize/2)-64:(xsize/2)+64] #only select the central region of the PSF
psf /= psf.max()
psf=psf*gaussGrid #apply a Gaussian taper to the PSF
psf_img = array2cv(psf)
#target_arr = target_img_grey[:,:]
#dirty_arr = cvfast_conv(target_arr,psf)
dirty_arr = cvfast_conv(target_img_lying,psf)
dirty_arr /= dirty_arr.max()
dirty_img = array2cv(dirty_arr)
cv.ShowImage("Antenna Layout",array2cv(layout_img_grey_arr))
cv.ShowImage("Target Image",array2cv(target_img_lying))
cv.ShowImage("Point Spread",psf_img)
cv.ShowImage("Observed Image",dirty_img)
if cv.WaitKey(50)!=-1:
break
cv.DestroyAllWindows()

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

@ -0,0 +1,48 @@
README Document for the webcam interactive interferometer
-----------------------------------------------------------------
Created: 26.2.14
Updated: 26.2.14
Required Equipment:
-extrenal USB webcam
-coins or small round objects
-flat, light colored area (A3 or A2 paper)
Software:
python script: gen_psf_interferometer_detect_skyim.py
test sky image: such as astro_test_image.jpg
The code is in the directory: /home/griffin/Downloads/interactiveInterferometer
To Run:
-----------------------------------------------------------------
1. before plugging in the webcam, run:
ls /dev/video*
2. plug in the webcam and again run:
ls /dev/video*
A new video device should appear, remember the ID number as this will be used in the script. For this example the external webcam is /dev/video1, so it has ID:1
3. run the script: gen_psf_interferometer_detect_skyim.py
For script help run: python gen_psf_interferometer_detect_skyim.py -h
To run the script with the webcam ID and test sky image: python gen_psf_interferometer_detect_skyim.py -c 1 -i /home/griffin/Downloads/interactiveInterferometer/astro_test_image.jpg
Changing Settings:
-----------------------------------------------------------------
A few parameters can be altered.
A Gaussian funstion is applied to the PSF, this can be disabled by commenting out the line:
psf=psf*gaussGrid
To change the size of the Gaussian function change the last two number in the line (they are in pixels):
gaussFunc=gauss2d(0.,0.,1.,30.,30.)
The circles are detected using the cv2.HoughCircles() function, it takes a number of parameters which are documented in the code and on the opencv webpage.

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

@ -0,0 +1,164 @@
#! /usr/bin/python
"""
Interferometer/PSF simulator
Created by: Jack Hickish
Minor Modifications by: Griffin Foster
TODO: add color
TODO: adjust detection paramters
TODO: add freeze/unfreeze command
TODO: add rotation command
"""
import cv2 #for ubuntu 12.04 install see: http://karytech.blogspot.com/2012/05/opencv-24-on-ubuntu-1204.html
import cv
import numpy as np
import time
import sys, optparse
def cvfast_conv(image,psf):
max_size = np.array([np.max([image.shape[0],psf.shape[0]]),np.max([image.shape[1],psf.shape[1]])])
n = cv.GetOptimalDFTSize(max_size[0]*2)
m = cv.GetOptimalDFTSize(max_size[1]*2)
imagePad=np.zeros((n,m))
imagePad[:image.shape[0],:image.shape[1]]=image
imageDirty=np.fft.irfft2(np.fft.rfft2(imagePad) * np.fft.rfft2(psf, imagePad.shape))
print image.shape, psf.shape, n,m
return imageDirty[psf.shape[0]/2:image.shape[0]+psf.shape[0]/2,psf.shape[1]/2:image.shape[1]+psf.shape[1]/2]
#return imagePad
def cv2array(im):
depth2dtype = {
cv.IPL_DEPTH_8U: 'uint8',
cv.IPL_DEPTH_8S: 'int8',
cv.IPL_DEPTH_16U: 'uint16',
cv.IPL_DEPTH_16S: 'int16',
cv.IPL_DEPTH_32S: 'int32',
cv.IPL_DEPTH_32F: 'float32',
cv.IPL_DEPTH_64F: 'float64',
}
arrdtype=im.depth
a = np.fromstring(
im.tostring(),
dtype=depth2dtype[im.depth],
count=im.width*im.height*im.nChannels)
a.shape = (im.height,im.width,im.nChannels)
return a
def array2cv(a):
dtype2depth = {
'uint8': cv.IPL_DEPTH_8U,
'int8': cv.IPL_DEPTH_8S,
'uint16': cv.IPL_DEPTH_16U,
'int16': cv.IPL_DEPTH_16S,
'int32': cv.IPL_DEPTH_32S,
'float32': cv.IPL_DEPTH_32F,
'float64': cv.IPL_DEPTH_64F,
}
try:
nChannels = a.shape[2]
except:
nChannels = 1
cv_im = cv.CreateImageHeader((a.shape[1],a.shape[0]),
dtype2depth[str(a.dtype)], nChannels)
cv.SetData(cv_im, a.tostring(),a.dtype.itemsize*nChannels*a.shape[1])
return cv_im
o = optparse.OptionParser()
o.set_usage('%prog [options]')
o.set_description(__doc__)
o.add_option('-i','--input',dest='input', default=None,
help='Input \'sky\' image, Default: HARDCODED')
o.add_option('-c','--camera',dest='camera', default=1, type='int',
help='Camera device ID in /dev/video*, Default: 1')
o.add_option('-r','--res',dest='res', default=4, type='int',
help='Resolution factor, increase this value to decrease the resolution, Default: 4')
opts, args = o.parse_args(sys.argv[1:])
CAMERA_DEVICE_INDEX=opts.camera #check /dev/, ID is attached to video device (0 is in the internal)
cv.NamedWindow("Antenna Layout", cv.CV_WINDOW_AUTOSIZE)
cv.NamedWindow("Target Image", cv.CV_WINDOW_AUTOSIZE)
cv.NamedWindow("Point Spread", cv.CV_WINDOW_AUTOSIZE)
cv.NamedWindow("Observed Image", cv.CV_WINDOW_AUTOSIZE)
cam0 = cv.CaptureFromCAM(CAMERA_DEVICE_INDEX)
if opts.input is None:
target_image = cv2.imread('/home/griffin/Downloads/interactiveInterferometer/astro_test_image.jpg')
else:
target_image=cv2.imread(opts.input)
target_img_grey = cv2.cvtColor(target_image,cv2.cv.CV_BGR2GRAY)
target_img_lying = target_img_grey.copy()
#saturated image
target_img_grey[target_img_grey>100] = 255
target_img_grey[target_img_grey<255] = 0
RESCALE_FACTOR=opts.res #decrease to change the effective resolution
ysize=480
xsize=640
#make a 2D Gaussian to modulate the PSF with
def gauss2d(x0,y0,amp,stdx,stdy):
return lambda x,y: amp*np.exp(-1.*( (((x-x0)**2.)/(2*stdx**2.)) + (((y-y0)**2.)/(2*stdy**2.)) ))
gaussFunc=gauss2d(0.,0.,1.,30.,30.)
xx = np.arange(xsize)-(xsize/2)
yy = np.arange(ysize)-(ysize/2)
xv, yv = np.meshgrid(xx, yy)
gaussGrid=gaussFunc(xv,yv)
while(True):
layout_img = cv.QueryFrame(cam0)
layout_img_grey = cv.CreateImage((layout_img.width,layout_img.height),layout_img.depth,1)
cv.CvtColor(layout_img,layout_img_grey,cv.CV_BGR2GRAY)
layout_img_grey_arr = cv2array(layout_img_grey)
station_locs = np.zeros([ysize/RESCALE_FACTOR,xsize/RESCALE_FACTOR])
#cv2.HoughCircles(image, method, dp, minDist, circles, param1, param2, minRadius, maxRadius)
# image: input webcam image size
# method: only cv.CV_HOUGH_GRADIENT exists
# dp: Inverse ratio of the accumulator resolution to the image resolution. this basically affects the min/max radius
# minDist: Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
# circles: set to None
# param1: threshold parameter
# param2: The smaller it is, the more false circles may be detected.
# minRadius: Minimum circle radius
# maxRadius: Maximum circle radius
circles = cv2.HoughCircles(layout_img_grey_arr, cv.CV_HOUGH_GRADIENT,2,10,None,100,35,5,30)
if circles is not None:
for cn,circle in enumerate(circles[0]):
x,y = circle[1],circle[0]
print "we have circle at %d,%d"%(x,y)
try:
layout_img_grey_arr[x-5:x+5,y-5:y+5]=255
except:
pass
station_locs[x/RESCALE_FACTOR,y/RESCALE_FACTOR]=1
psf = np.fft.fftshift(np.abs(np.fft.fft2(station_locs,s=[ysize,xsize]))**2)
#psf=psf[(ysize/2)-64:(ysize/2)+64,(xsize/2)-64:(xsize/2)+64] #only select the central region of the PSF
psf /= psf.max()
psf=psf*gaussGrid #apply a Gaussian taper to the PSF
psf_img = array2cv(psf)
#target_arr = target_img_grey[:,:]
#dirty_arr = cvfast_conv(target_arr,psf)
dirty_arr = cvfast_conv(target_img_lying,psf)
dirty_arr /= dirty_arr.max()
dirty_img = array2cv(dirty_arr)
cv.ShowImage("Antenna Layout",array2cv(layout_img_grey_arr))
cv.ShowImage("Target Image",array2cv(target_img_lying))
cv.ShowImage("Point Spread",psf_img)
cv.ShowImage("Observed Image",dirty_img)
if cv.WaitKey(50)!=-1:
break
cv.DestroyAllWindows()

@ -0,0 +1,216 @@
#! /usr/bin/python
"""
Interferometer/PSF simulator
Created by: Jack Hickish
Minor Modifications by: Griffin Foster
Added threshold detection option to allow non-circular layouts (i.e. handdrawn) Charles Copley
TODO: add color
TODO: adjust detection paramters
TODO: add freeze/unfreeze command
TODO: add rotation command
"""
import cv2 #for ubuntu 12.04 install see: http://karytech.blogspot.com/2012/05/opencv-24-on-ubuntu-1204.html
import cv
import numpy as np
import time
import sys, optparse
import pdb
import matplotlib.pylab as plt
def cvfast_conv(image,psf):
max_size = np.array([np.max([image.shape[0],psf.shape[0]]),np.max([image.shape[1],psf.shape[1]])])
n = cv.GetOptimalDFTSize(max_size[0]*2)
m = cv.GetOptimalDFTSize(max_size[1]*2)
imagePad=np.zeros((n,m))
imagePad[:image.shape[0],:image.shape[1]]=image
imageDirty=np.fft.irfft2(np.fft.rfft2(imagePad) * np.fft.rfft2(psf, imagePad.shape))
print image.shape, psf.shape, n,m
return imageDirty[psf.shape[0]/2:image.shape[0]+psf.shape[0]/2,psf.shape[1]/2:image.shape[1]+psf.shape[1]/2]
#return imagePad
def cv2array(im):
depth2dtype = {
cv.IPL_DEPTH_8U: 'uint8',
cv.IPL_DEPTH_8S: 'int8',
cv.IPL_DEPTH_16U: 'uint16',
cv.IPL_DEPTH_16S: 'int16',
cv.IPL_DEPTH_32S: 'int32',
cv.IPL_DEPTH_32F: 'float32',
cv.IPL_DEPTH_64F: 'float64',
}
arrdtype=im.depth
a = np.fromstring(
im.tostring(),
dtype=depth2dtype[im.depth],
count=im.width*im.height*im.nChannels)
a.shape = (im.height,im.width,im.nChannels)
return a
def edgeDetect(image):
##function that uses edge detection thresholding to find the locations of the points
# pdb.set_trace()
image=~image ##we need to invert so that the points are turned white.
thresh1 = cv2.Canny(image,70,255) ##first set up the thresholding
contours, hierarchy = cv2.findContours(thresh1,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
pos=[]
old=[]
new=[]
for cnt in range(len(contours)):
peri = cv2.arcLength(contours[cnt], True)
approx = cv2.approxPolyDP(contours[cnt], 0.02 * peri, True)
# cv2.drawContours(thresh1, [approx], -1, (255, 255, 0), 6)
M=cv2.moments(contours[cnt])
try:
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
cv2.circle(image,(cx,cy),10,(255,255,0),5)
# pdb.set_trace()
new=[cx,cy] #set this up to avoid doubling positions contours
if(old!=new):
pos.append([cx,cy])
old=new
except:
print 'error'
try:
print cnt,cx,cy
except:
print 'error'
cv2.imshow("image",image)
# cv2.waitKey(0)
return [frame,pos]
def array2cv(a):
dtype2depth = {
'uint8': cv.IPL_DEPTH_8U,
'int8': cv.IPL_DEPTH_8S,
'uint16': cv.IPL_DEPTH_16U,
'int16': cv.IPL_DEPTH_16S,
'int32': cv.IPL_DEPTH_32S,
'float32': cv.IPL_DEPTH_32F,
'float64': cv.IPL_DEPTH_64F,
}
try:
nChannels = a.shape[2]
except:
nChannels = 1
cv_im = cv.CreateImageHeader((a.shape[1],a.shape[0]),
dtype2depth[str(a.dtype)], nChannels)
cv.SetData(cv_im, a.tostring(),a.dtype.itemsize*nChannels*a.shape[1])
return cv_im
o = optparse.OptionParser()
o.set_usage('%prog [options]')
o.set_description(__doc__)
o.add_option('-i','--input',dest='input', default=None,
help='Input \'sky\' image, Default: HARDCODED')
o.add_option('-c','--camera',dest='camera', default=1, type='int',
help='Camera device ID in /dev/video*, Default: 1')
o.add_option('-r','--res',dest='res', default=1, type='int',
help='Resolution factor, increase this value to decrease the resolution, Default: 4')
opts, args = o.parse_args(sys.argv[1:])
CAMERA_DEVICE_INDEX=opts.camera #check /dev/, ID is attached to video device (0 is in the internal)
#cv.NamedWindow("Antenna Layout", cv.CV_WINDOW_AUTOSIZE)
#cv.NamedWindow("Target Image", cv.CV_WINDOW_AUTOSIZE)
#cv.NamedWindow("Point Spread", cv.CV_WINDOW_AUTOSIZE)
#cv.NamedWindow("Observed Image", cv.CV_WINDOW_AUTOSIZE)
#cam0 = cv.CaptureFromCAM(CAMERA_DEVICE_INDEX)
if opts.input is None:
target_image = cv2.imread('/home/griffin/Downloads/interactiveInterferometer/astro_test_image.jpg')
else:
target_image=cv2.imread(opts.input)
target_img_grey = cv2.cvtColor(target_image,cv2.cv.CV_BGR2GRAY)
target_img_lying = target_img_grey.copy()
#saturated image
target_img_grey[target_img_grey>100] = 255
target_img_grey[target_img_grey<255] = 0
RESCALE_FACTOR=opts.res #decrease to change the effective resolution
ysize=480
xsize=640
#make a 2D Gaussian to modulate the PSF with
def gauss2d(x0,y0,amp,stdx,stdy):
return lambda x,y: amp*np.exp(-1.*( (((x-x0)**2.)/(2*stdx**2.)) + (((y-y0)**2.)/(2*stdy**2.)) ))
gaussFunc=gauss2d(0.,0.,1.,30.,30.)
xx = np.arange(xsize)-(xsize/2)
yy = np.arange(ysize)-(ysize/2)
xv, yv = np.meshgrid(xx, yy)
gaussGrid=gaussFunc(xv,yv)
while(True):
# pdb.set_trace()
cam0t=cv2.VideoCapture(CAMERA_DEVICE_INDEX)
ret,frame = cam0t.read()
cam0t.release()
layout_img=frame
#ayout_img = cv.QueryFrame(cam0)
# layout_img_grey = cv.CreateImage((layout_img.width,layout_img.height),layout_img.depth,1)
# cv.CvtColor(layout_img,layout_img_grey,cv.CV_BGR2GRAY)
#ayout_img_grey_arr = cv2array(layout_img_grey)
layout_img_grey_arr = cv2.cvtColor(layout_img,cv2.COLOR_BGR2GRAY)
station_locs = np.zeros([ysize/RESCALE_FACTOR,xsize/RESCALE_FACTOR])
#cv2.HoughCircles(image, method, dp, minDist, circles, param1, param2, minRadius, maxRadius)
# image: input webcam image size
# method: only cv.CV_HOUGH_GRADIENT exists
# dp: Inverse ratio of the accumulator resolution to the image resolution. this basically affects the min/max radius
# minDist: Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
# circles: set to None
# param1: threshold parameter
# param2: The smaller it is, the more false circles may be detected.
# minRadius: Minimum circle radius
# maxRadius: Maximum circle radius
# circles = cv2.HoughCircles(layout_img_grey_arr, cv.CV_HOUGH_GRADIENT,2,10,None,100,35,5,30)
[layout_img_grey_arr,targets]=edgeDetect(layout_img_grey_arr)
circles=np.array(targets)
if circles is not None:
for cn in range(1,len(circles)):
## pdb.set_trace()
y,x = circles[cn]
print "we have circle at %d,%d"%(x,y)
try:
layout_img_grey_arr[x-5:x+5,y-5:y+5]=255
except:
pass
# pdb.set_trace()
station_locs[x/RESCALE_FACTOR,y/RESCALE_FACTOR]=1
psf = np.fft.fftshift(np.abs(np.fft.fft2(station_locs,s=[ysize,xsize]))**2)
#psf=psf[(ysize/2)-64:(ysize/2)+64,(xsize/2)-64:(xsize/2)+64] #only select the central region of the PSF
psf /= psf.max()
psf=psf*gaussGrid #apply a Gaussian taper to the PSF
psf_img = array2cv(psf)
#target_arr = target_img_grey[:,:]
#dirty_arr = cvfast_conv(target_arr,psf)
dirty_arr = cvfast_conv(target_img_lying,psf)
dirty_arr /= dirty_arr.max()
dirty_img = array2cv(dirty_arr)
# pdb.set_trace()
cv2.imshow("Antenna Layout",layout_img_grey_arr)
cv2.imshow("Target Image",target_img_lying)
# cv2.imshow("Point Spread",psf_img)
# cv2.imshow("Observed Image",dirty_img)
#cv.ShowImage("Antenna Layout",array2cv(layout_img_grey_arr))
#cv.ShowImage("Target Image",array2cv(target_img_lying))
cv.ShowImage("Point Spread",psf_img)
cv.ShowImage("Observed Image",dirty_img)
#v.WaitKey(0)
if cv2.waitKey(50)!=-1:
break
cv.DestroyAllWindows()

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

@ -0,0 +1,62 @@
import cv
import cv2
import numpy as np
import time
import sys, optparse
import matplotlib.pyplot as plt
#rame=cv2.imread('test.jpg',0)
cam0t=cv2.VideoCapture(1)
ret,frame = cam0t.read()
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
frame=~frame
cv2.imshow('image',frame)
cv2.waitKey(0)
edges=cv2.Canny(frame,70,255)
#ret,thresh1 = cv2.threshold(hsv,90,255,cv2.THRESH_BINARY)
#thresh1=~thresh1
cv2.imshow('image',edges)
cv2.waitKey(0)
contours, hierarchy = cv2.findContours(edges,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#filledI = np.zeros(thresh1.shape[0:2]).astype('uint8')
#convexI = np.zeros(thresh1.shape[0:2]).astype('uint8')
cv2.drawContours(edges, contours, 0, (0,255,0), 10)
cv2.imshow('image',edges)
cv2.waitKey(0)
contours= sorted(contours, key = cv2.contourArea, reverse = False)
pos=[]
for cnt in range(len(contours)):
peri = cv2.arcLength(contours[cnt], True)
approx = cv2.approxPolyDP(contours[cnt], 0.02 * peri, True)
# cv2.drawContours(thresh1, [approx], -1, (255, 255, 0), 6)
M=cv2.moments(contours[cnt])
try:
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
cv2.circle(edges,(cx,cy),10,(255,255,0),5)
pos.append([cx,cy])
except:
print 'error'
try:
print cnt,cx,cy
except:
print 'error'
cv2.imshow('image',edges)
cv2.waitKey(30)
cv2.imshow('image',frame)
cv2.waitKey(30)
#cv2.destroyAllWindows()

@ -0,0 +1,22 @@
import cv
import cv2
import numpy as np
import time
import sys, optparse
CAMERA_DEVICE_INDEX=0 #check /dev/, ID is attached to video device (0 is in the internal)
cam0= cv2.VideoCapture(0)
ret,frame = cam0.read()
cv2.imshow('frame',frame)
cv2.imwrite('test.jpg',frame)
cv2.waitKey(1)
cam0.release()
cv2.destroyAllWindows()
Loading…
Cancel
Save