def build_problem(img_kind, subdir = "data/"): subdir = "data/" classes = [] data = [] the_ones = glob.glob(subdir + "f_" + img_kind + "*.jpg") all_of_them = glob.glob(subdir + "f_*_*.jpg") the_others = [] for x in all_of_them: if the_ones.count(x) < 1: the_others.append(x) for x in the_ones: classes.append(1) data.append(get_image_features(cv.LoadImageM(x), True, img_kind)) for x in the_others: classes.append(-1) data.append(get_image_features(cv.LoadImageM(x), True, img_kind)) prob = svm.svm_problem(classes, data) return prob
def pca_test(img_kind): import pylab as pl from mpl_toolkits.mplot3d import Axes3D subdir = "data/" classes = [] data = [] the_ones = glob.glob(subdir + "f_" + img_kind + "*.jpg") all_of_them = glob.glob(subdir + "f_*_*.jpg") the_others = [] for x in all_of_them: if the_ones.count(x) < 1: the_others.append(x) for x in the_ones: classes.append(1) data.append(get_image_features(cv.LoadImageM(x))) for x in the_others: classes.append(-1) data.append(get_image_features(cv.LoadImageM(x))) pca = PCA(46, whiten=True) print 'fiting' pca.fit(data) print 'transforming' X_r = pca.transform(data) print '----' print X_r.shape x0 = [x[0] for x in X_r] x1 = [x[1] for x in X_r] pl.figure() for i in xrange(0,len(x0)): if classes[i] == 1: pl.scatter(x0[i], x1[i], c = 'r') else: pl.scatter(x0[i], x1[i], c = 'b') # for c, i, target_name in zip("rg", [1, -1], target_names): # pl.scatter(X_r[classes == i, 0], X_r[classes == i, 1], c=c, label=target_name) pl.legend() pl.title('PCA of dataset') pl.show()
def test_model(img_kind): subdir = "data/" model = svmutil.svm_load_model(subdir + img_kind + '.model') print "Finished Loading Model" total_count = 0 correct_count = 0 wrong_count = 0 the_ones = glob.glob(subdir + "f_" + img_kind + "*.jpg") all_of_them = glob.glob(subdir + "f_*_*.jpg") the_others = [] for x in all_of_them: total_count += 1 if the_ones.count(x) < 1: the_others.append(x) for x in the_ones: img = cv.LoadImageM(x) cv.ShowImage("img", img) cv.WaitKey(10) img_features = get_image_features(img, True, img_kind) predict_input_data = [] predict_input_data.append(img_features) (val, val_2, val_3) = svmutil.svm_predict([1], predict_input_data, model) if int(val[0]) == 1: print 'correct' correct_count += 1 else: wrong_count += 1 for x in the_others: img = cv.LoadImageM(x) cv.ShowImage("img", img) cv.WaitKey(10) img_features = get_image_features(img, True, img_kind) predict_input_data = [] predict_input_data.append(img_features) (val, val_2, val_3) = svmutil.svm_predict([1], predict_input_data, model) if int(val[0]) == -1: correct_count += 1 else: wrong_count += 1 print "Total Pictures: " + str(total_count) print "Correct: " + str(correct_count) print "Wrong: " + str(wrong_count) print "Accuracy: " + str(correct_count/float(total_count) * 100) + '%'
def LoadDisplay(): img = cv.LoadImageM(k, cv.CV_LOAD_IMAGE_COLOR) print img cv.NamedWindow("LoadAndDisplay", cv.CV_WINDOW_AUTOSIZE) cv.ShowImage("LoadAndDisplay", img) cv.WaitKey(0) cv.DestroyWindow("LoadAndDisplay")
def genFeatres(img_list): network = slminit() filenames = img_list index = 0 faceVectors = [] for img in filenames: entry1 = img src1 = cv.LoadImageM(entry1) gray_full1 = cv.CreateImage(cv.GetSize(src1), 8, 1) grayim1 = cv.CreateImage((200, 200), 8, 1) cv.CvtColor(src1, gray_full1, cv.CV_BGR2GRAY) cv.Resize(gray_full1, grayim1, interpolation=cv.CV_INTER_CUBIC) gray1 = cv.GetMat(grayim1) im_array1 = np.asarray(gray1).astype('f') # -- compute feature map, shape [height, width, depth] f_map1 = slmprop(im_array1, network) f_map_dims1 = f_map1.shape image_vector = [] for j in range(f_map_dims1[0]): for k in range(f_map_dims1[1]): for l in range(f_map_dims1[2]): image_vector.append(f_map1[j][k][l]) print index index = index + 1 faceVectors.append(np.asarray(image_vector)) return faceVectors
def genView(panopath, outpath, orientation, viewdir, detail): # panopath: location of raster, depth and plane_pano images # outpath: location to put generated view, depth, and plane images # orientation: [yaw, pitch, roll] of panorama (in degrees) # viewdir: clock-based view; in set [2,3,4,8,9,10] for database # detail: 0 = 768x512 with 60d fov, 1 = 2500x1200 with 90d fov # local constants start = time.time() pi = np.pi width, height, fov = (2500, 1200, 90) if detail else (768, 512, 60) # view details Rpano = geom.RfromYPR(orientation[0],orientation[1],orientation[2]) Yview = np.mod( orientation[0] + 30*viewdir, 360 ) Rview = geom.RfromYPR(Yview, 0, 0) Kview = geom.cameramat(width, height, fov*pi/180) Kinv = alg.inv(Kview) # Load image pano, depth pano, and plane pano images cvIP = cv.LoadImageM( os.path.join(panopath,'raster.jpg'), cv.CV_LOAD_IMAGE_UNCHANGED ) cvDP = cv.fromarray( np.asarray( Image.open( os.path.join(panopath,'depth.png') ) ) ) pp = np.asarray( Image.open( os.path.join(panopath,'plane_pano.png') ) ).copy() vals = set(list(pp.reshape(-1))) vals.remove(255) gnd = max(vals) pp[pp==gnd] = np.uint8(0) cvPP = cv.fromarray(pp) # load pixel map pix = np.append(np.array(np.meshgrid(range(width),range(height))).reshape(2,-1),np.ones([1,width*height]),0) midpoint = time.time() print 'Loading pano images took ' + str(midpoint-start) + ' seconds.' # Create output openCV matrices cvI = cv.CreateMat(height,width,cv.CV_8UC3) cvD = cv.CreateMat(height,width,cv.CV_32SC1) cvP = cv.CreateMat(height,width,cv.CV_8UC1) # compute mappings ray = np.dot( np.transpose(Rpano), np.dot( Rview, np.dot( Kinv, pix ) ) ) yaw, pitch = np.arctan2( ray[0,:] , ray[2,:] ) , np.arctan2( -ray[1,:] , np.sqrt((np.array([ray[0,:],ray[2,:]])**2).sum(0)) ) ix, iy = cv.fromarray(np.array(8192/(2*pi)*(pi+yaw),np.float32).reshape(height,width)), cv.fromarray(np.array(4096/pi*(pi/2-pitch),np.float32).reshape(height,width)) dx, dy = cv.fromarray(np.array(5000/(2*pi)*(pi+yaw),np.float32).reshape(height,width)), cv.fromarray(np.array(2500/pi*(pi/2-pitch),np.float32).reshape(height,width)) px, py = cv.fromarray(np.array(1000/(2*pi)*(pi+yaw),np.float32).reshape(height,width)), cv.fromarray(np.array( 500/pi*(pi/2-pitch),np.float32).reshape(height,width)) # call remap function cv.Remap(cvIP,cvI,ix,iy,cv.CV_INTER_CUBIC) cv.Remap(cvDP,cvD,dx,dy,cv.CV_INTER_NN) cv.Remap(cvPP,cvP,px,py,cv.CV_INTER_NN) # write images to file Image.fromarray(np.array(cvI)[:,:,[2,1,0]]).save(os.path.join(outpath,'view.jpg'),'jpeg') Image.fromarray(np.array(cvD)).save(os.path.join(outpath,'depth.png'),'png') Image.fromarray(np.array(cvP)).save(os.path.join(outpath,'plane.png'),'png') print 'Generating views from pano took ' + str(time.time()-midpoint) + ' seconds.'
def convertto(): image=cv.LoadImageM(getpath(),cv.CV_LOAD_IMAGE_COLOR) newimage=cv.CreateMat(image.rows,image.cols,image.type) cv.SetZero(newimage) cv.ConvertScale(image,newimage,2.2,50.0) display(image,"Source") display(newimage,"Destination") cv.WaitKey(0)
def resize(): original = cv.LoadImageM(getpath()) thumbnail = cv.CreateMat(original.rows / 10, original.cols / 10, cv2.cv.CV_8UC3) cv.Resize(original, thumbnail) cv.NamedWindow("destination", 1) cv.ShowImage("destination", thumbnail) cv.WaitKey(0)
def medianfiltering(): src = cv.LoadImageM(k, cv.CV_LOAD_IMAGE_COLOR) dst = cv.CreateImage((src.width, src.height), 8, src.channels) cv.SetZero(dst) cv.NamedWindow("Median Filtering", 1) cv.NamedWindow("After Filtering", 1) cv.Smooth(src, dst, cv.CV_MEDIAN, 9, 9) cv.ShowImage("Median Filtering", src) cv.ShowImage("After Filtering", dst) cv.WaitKey(0)
def load_frames(inputDir, nframes, level): # Load images from the input directory frames = [] for k in range(nframes): im = cv.LoadImageM(inputDir + "/" + str(level) + str(k) + ".jpg", cv.CV_LOAD_IMAGE_COLOR) frames.append(np.asarray(im)) #end for return frames
def data_gen(img_kind): subdir = "data/" extension = '.data' file_path = subdir + img_kind + extension output_file = open(file_path, 'w+') the_ones = glob.glob(subdir + "f_" + img_kind + "*.jpg") all_of_them = glob.glob(subdir + "f_*_*.jpg") the_others = [] for x in all_of_them: if the_ones.count(x) < 1: the_others.append(x) for x in the_ones: img_features = get_image_features(cv.LoadImageM(x), True, img_kind) class_label = 1 #write label in a new line output_file.write(str(class_label)) #write features one by one and increment the index for i in xrange(1,len(img_features)): output_file.write(' ' + str(i) + ':' + str(img_features[i-1])) #write newline output_file.write("\n") print x for x in the_others: img_features = get_image_features(cv.LoadImageM(x), True, img_kind) class_label = -1 #write label in a new line output_file.write(str(class_label)) #write features one by one and increment the index for i in xrange(1,len(img_features)): output_file.write(' ' + str(i) + ':' + str(img_features[i-1])) #write newline output_file.write("\n") print x output_file.close()
def fit_pca_and_lda(img_kind): print img_kind global pca global lda global subdir subdir = "data/train/" classes = [] data = [] the_ones = glob.glob(subdir + "f_" + img_kind + "*.jpg") all_of_them = glob.glob(subdir + "f_*_*.jpg") the_others = [] for x in all_of_them: if the_ones.count(x) < 1: the_others.append(x) for x in the_ones: classes.append(1) data.append(get_image_features(cv.LoadImageM(x))) for x in the_others: classes.append(-1) data.append(get_image_features(cv.LoadImageM(x))) # c_pca = PCA(n_components=30) # print 'fiting-pca' # c_pca.fit(data) c_lda = LDA(n_components=2) print 'fiting-lda' c_lda.fit(data, classes) print 'finish' # pca[img_kind] = c_pca lda[img_kind] = c_lda
def process(infile, outfile): image = cv.LoadImageM(infile); if image: faces = detectObjects(image) im = Image.open(infile) if faces: draw = ImageDraw.Draw(im) for f in faces: draw.rectangle(f, outline=(255, 0, 0)) im.save(outfile, "JPEG", quality=100) else: print "Error: cannot detect faces on %s" % infile
#!/usr/bin/env python import sys import cv2.cv as cv def findstereocorrespondence(image_left, image_right): # image_left and image_right are the input 8-bit single-channel images # from the left and the right cameras, respectively (r, c) = (image_left.rows, image_left.cols) disparity_left = cv.CreateMat(r, c, cv.CV_16S) disparity_right = cv.CreateMat(r, c, cv.CV_16S) state = cv.CreateStereoGCState(16, 2) cv.FindStereoCorrespondenceGC(image_left, image_right, disparity_left, disparity_right, state, 0) return (disparity_left, disparity_right) if __name__ == '__main__': (l, r) = [cv.LoadImageM(f, cv.CV_LOAD_IMAGE_GRAYSCALE) for f in sys.argv[1:]] (disparity_left, disparity_right) = findstereocorrespondence(l, r) disparity_left_visual = cv.CreateMat(l.rows, l.cols, cv.CV_8U) cv.ConvertScale(disparity_left, disparity_left_visual, -16) cv.SaveImage("disparity.pgm", disparity_left_visual)
# for i in range(2): # convert store[i] # convert mouse_c[i] # if compare(mouse_c[stored[i]] == mouse_c[i]) == false: # check =1 # break # if imagecheck == 0: # pygame.display.quit() #roi is the object or region of object we need to find # cv2.mat =cv2.imread('ball.png') #hsv = cv2.cvtColor(roi,cv2.COLOR_BGR2HSV) path = 'ball.png' mat1 = cv.LoadImageM(path, cv.CV_LOAD_IMAGE_UNCHANGED) tex = 0 #target is the image we search in path = 'bg.jpg' mat2 = cv.LoadImageM(path, cv.CV_LOAD_IMAGE_UNCHANGED) #hsvt = cv2.cvtColor(target,cv2.COLOR_BGR2HSV) for x in xrange(mat1.cols): for y in xrange(mat1.rows): # multiply all 3 components by 0.5 if (mat1[y, x] != mat2[y, x]): # tuple(c*0.5 for c in mat[y, x]) tex = 1 print "we r here" #print mat1[y,x] #print mat2[y,x]
while (1): if liveIP: #capture images from cameras, store images to file urllib.urlretrieve(url_west, fname_west) urllib.urlretrieve(url_east, fname_east) else: num_base = (num_base + 1) % 145 west_num = west_offset + num_base east_num = east_offset + num_base fname_west = dirList[west_num] fname_east = dirList[east_num] cv.WaitKey(2000) #wait for 2 seconds so I can see the output #open the images from file frame_west = cv.LoadImageM(fname_west, cv.CV_LOAD_IMAGE_COLOR) frame_east = cv.LoadImageM(fname_east, cv.CV_LOAD_IMAGE_COLOR) #find the blimp with one camera, frame is passed in by reference centroids = procImg(frame_west, "west", dispMore) centx_west = centroids[0] centy_west = centroids[1] #find the blimp with one camera, frame is passed in by reference centroids = procImg(frame_east, "east", dispMore) centx_east = centroids[0] centy_east = centroids[1] #decimate the resulting images small_west = cv.CreateImage((int(0.25 * cv.GetSize(frame_west)[0]), int(0.25 * cv.GetSize(frame_west)[1])), 8, 3)
def loadImgM(num): return cv.LoadImageM("logs/img_{:05}.pgm".format(num), cv.CV_LOAD_IMAGE_GRAYSCALE)
import cv2 import cv2.cv as cv import numpy as np im = cv.LoadImageM("lena.jpg") #size = (960,600) size = cv.GetSize(im) #size=im.size() dst = cv.CreateImage(size, 8, 3) smoothed = cv.CreateImage(size, 8, 3) dst3 = cv.CreateImage(size, 8, 3) cv.Resize(im,dst) for i in range(4): cv.Smooth(dst,smoothed,cv.CV_BILATERAL, 30,1,32,32) cv.Smooth(smoothed,dst,cv.CV_BILATERAL, 30,1,32,32) cv.Smooth(dst,smoothed,cv.CV_BILATERAL, 30,1,32,32) lap = cv.CreateImage(cv.GetSize(smoothed), cv.IPL_DEPTH_16S, 3) #laplace = cv.Laplace(smoothed, lap) gray = cv.CreateImage(cv.GetSize(smoothed), 8, 1) canny = cv.CreateImage(cv.GetSize(smoothed), 8, 1) cv.CvtColor(smoothed, gray, cv.CV_BGR2GRAY) cv.Canny(gray,canny,20,20,3) #ret,thresh = cv.threshold(imgray,127,255,0) cv.NamedWindow('Original') cv.MoveWindow('Original', 10, 10) cv.ShowImage('Original', im) cv.NamedWindow('Smoothed')
centerX = x centerY = y if __name__ == '__main__': capture = cv.CaptureFromCAM(0) #capture = cv.CaptureFromFile("out.mpg") # not working, for unknown reasons cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 320) cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 240) polar = cv.CreateImage((360, 360), 8, 3) img = cv.CreateImage((320, 240), 8, 3) im = cv.CreateImage((320, 240), 8, 1) rt = cv.CreateImage((320, 240), 8, 1) lt = cv.CreateImage((320, 240), 8, 1) lm = cv.LoadImageM("leftmask-K-2013-02-27.bmp", cv.CV_LOAD_IMAGE_GRAYSCALE) rm = cv.LoadImageM("rightmask-K-2013-02-27.bmp", cv.CV_LOAD_IMAGE_GRAYSCALE) cv.NamedWindow('cam') cv.NamedWindow('left') cv.NamedWindow('right') cv.SetMouseCallback("cam", on_mouse) on_mouse(cv.CV_EVENT_LBUTTONDOWN, centerX, centerY, None, None) font = cv.InitFont(cv.CV_FONT_HERSHEY_PLAIN, 1.0, 1.0) M = 60 while True: img = cv.QueryFrame(capture)
def srgb2lin(x): a = 0.055 return numpy.where(x <= 0.04045, x * (1.0 / 12.92), numpy.power((x + a) * (1.0 / (1 + a)), 2.4)) def lin2srgb(x): a = 0.055 return numpy.where(x <= 0.0031308, x * 12.92, (1 + a) * numpy.power(x, 1 / 2.4) - a) if __name__ == "__main__": if len(sys.argv) > 1: img0 = cv.LoadImageM(sys.argv[1], cv.CV_LOAD_IMAGE_COLOR) else: url = 'http://code.opencv.org/svn/opencv/trunk/opencv/samples/c/lena.jpg' filedata = urllib2.urlopen(url).read() imagefiledata = cv.CreateMatHeader(1, len(filedata), cv.CV_8UC1) cv.SetData(imagefiledata, filedata, len(filedata)) img0 = cv.DecodeImageM(imagefiledata, cv.CV_LOAD_IMAGE_COLOR) cv.NamedWindow("original", 1) cv.ShowImage("original", img0) # Image was originally bytes in range 0-255. Turn it into an array of floats in range 0.0 - 1.0 n = numpy.asarray(img0) / 255.0 # Use NumPy to do some transformations on the image
import cv2.cv as cv #Import functions from OpenCV #first read image in gray scale. GrayImg = cv.LoadImageM("cat.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE) SmoothGrayImg = cv.CreateMat(GrayImg.rows, GrayImg.cols, cv.CV_BLUR_NO_SCALE) cv.Smooth(GrayImg, SmoothGrayImg, cv.CV_MEDIAN, param1=5, param2=0, param3=0, param4=0) cv.SaveImage("Grey image.png", GrayImg) cv.SaveImage("GraySmooth image.png", SmoothGrayImg) #edge detection EdgeDetection_Img = cv.CreateImage(cv.GetSize(SmoothGrayImg), cv.IPL_DEPTH_16S, cv.CV_BLUR_NO_SCALE) cv.Laplace(SmoothGrayImg, EdgeDetection_Img) cv.SaveImage(" EdgeDetection image.png", EdgeDetection_Img) # set threshold Thresholding = cv.CreateImage(cv.GetSize(EdgeDetection_Img), cv.IPL_DEPTH_16S, cv.CV_BLUR_NO_SCALE) cv.Threshold(EdgeDetection_Img, Thresholding, 20, 400, cv.CV_THRESH_BINARY_INV) cv.SaveImage("Thresholding.png", Thresholding) #Output from bilateral filter im = cv.LoadImageM("cat.jpg") BilateralImg = cv.CreateImage(cv.GetSize(im), cv.IPL_DEPTH_8U, 3) cv.CvtColor(im, BilateralImg, cv.CV_RGB2Lab)
text2 = text2.replace('O', '0') return text1 + text2 tools = pyocr.get_available_tools() if len(tools) == 0: print("No OCR tool found") sys.exit(1) path_root = '/home/ivan/dev/pydev/lab/labtrans/plotter/data/cam/' # 20130626_115022_imagemPlaca.jpg for f in os.listdir(path_root): #for f in ['20130626_115022_imagemPlaca.jpg']: print f image = cv.LoadImageM(path_root + f) for plate in anpr.detect_plates(image): #quick_show(image) #quick_show(plate) #zzz = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 3) #cv.Smooth(plate, zzz) # #cv.PyrMeanShiftFiltering(plate, zzz, 40, 15) foo = anpr.greyscale(plate) segmented = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) bar = cv.CreateImage(cv.GetSize(plate), cv.IPL_DEPTH_8U, 1) cv.EqualizeHist(foo, segmented) cv.AdaptiveThreshold( segmented, bar, 255, cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C, cv.CV_THRESH_BINARY_INV,
break tex = 0 path = [] for mcount in range(9): mcounter = mcount + 1 path.append( os.path.join('C:\Users\Rohun\Desktop\game1', "IMG-%s.png" % mcounter)) mat = [] checkmat = [] for ncount in range(9): mat.append(cv.LoadImageM(path[ncount], cv.CV_LOAD_IMAGE_UNCHANGED)) checkmat.append( cv.LoadImageM(path[stored[ncount]], cv.CV_LOAD_IMAGE_UNCHANGED)) #hsvt = cv2.cvtColor(target,cv2.COLOR_BGR2HSV) for k in range(9): for i in xrange(mat[0].cols): for j in xrange(mat[0].rows): # multiply all 3 components by 0.5 if (mat[k][j, i] != checkmat[k][j, i]): # tuple(c*0.5 for c in mat[y, x]) tex = 1 # print "we r here" if (tex == 0): #pygame.display.quit()
def convert(): im = cv.LoadImageM(getpath()) cv.SaveImage("C:\\Users\\raj\\Desktop\\s5.png", im) display(im, "PNG FROM JPG") cv.WaitKey(0)
# saturation varies from 0 (black-gray-white) to # 255 (pure spectrum color) s_ranges = [0, 255] ranges = [h_ranges, s_ranges] scale = 10 hist = cv.CreateHist([h_bins, s_bins], cv.CV_HIST_ARRAY, ranges, 1) cv.CalcHist([cv.GetImage(i) for i in planes], hist) (_, max_value, _, _) = cv.GetMinMaxHistValue(hist) hist_img = cv.CreateImage((h_bins * scale, s_bins * scale), 8, 3) for h in range(h_bins): for s in range(s_bins): bin_val = cv.QueryHistValue_2D(hist, h, s) intensity = cv.Round(bin_val * 255 / max_value) cv.Rectangle(hist_img, (h * scale, s * scale), ((h + 1) * scale - 1, (s + 1) * scale - 1), cv.RGB(intensity, intensity, intensity), cv.CV_FILLED) return hist_img if __name__ == '__main__': src = cv.LoadImageM(sys.argv[1]) cv.NamedWindow("Source", 1) cv.ShowImage("Source", src) cv.NamedWindow("H-S Histogram", 1) cv.ShowImage("H-S Histogram", hs_histogram(src)) cv.WaitKey(0)
temp1 = x[1] temp2 = y[1] screen.blit(mouse_c[1], (temp1, temp2)) for k in range(2): for f in range(2): if x[k] == 400 and y[k] == 100 + 100 * f: stored[f] = k tex = 0 path = ['basket.png', 'ball.png'] mat = [] checkmat = [] mat.append(cv.LoadImageM(path[0], cv.CV_LOAD_IMAGE_UNCHANGED)) mat.append(cv.LoadImageM(path[1], cv.CV_LOAD_IMAGE_UNCHANGED)) checkmat.append(cv.LoadImageM(path[stored[0]], cv.CV_LOAD_IMAGE_UNCHANGED)) checkmat.append(cv.LoadImageM(path[stored[1]], cv.CV_LOAD_IMAGE_UNCHANGED)) #hsvt = cv2.cvtColor(target,cv2.COLOR_BGR2HSV) for k in range(2): for i in xrange(mat[0].cols): for j in xrange(mat[0].rows): # multiply all 3 components by 0.5 if (mat[k][j, i] != checkmat[k][j, i]): # tuple(c*0.5 for c in mat[y, x]) tex = 1 # print "we r here"
import cv2 from cv2 import cv from database import * src_image = cv.LoadImageM(getpath(), cv.CV_LOAD_IMAGE_COLOR) dst_image = cv.CreateImage((src_image.width, src_image.height), 8, src_image.channels) cv.SetZero(dst_image) #src_image=cv.LoadImageM("C:\\Users\\raj\\Desktop\\image processing and computer vision\\pictures\\s4.jpg") def display(img, name): cv.NamedWindow(name, 1) cv.ShowImage(name, img)
def drawfilledpolygon(): cv.FillPoly(img,[[(50,50),(100,100)],[(120,20),(150,30)],[(50,50),(120,20)],[(100,100),(150,30)]],(255,255,255),4,1) display(img,"Destination") cv.WaitKey(0) if __name__=='__main__': drawcircle() ''' import cv2 from cv2 import cv from GUI import * from database import * img = cv.LoadImageM(getpath(), cv.CV_WINDOW_AUTOSIZE) def ellipsedraw(): cv.Ellipse(img, (50, 150), (40, 80), 100.0, 0.0, 360.0, (0, 0, 0), 8, 2) display(img, "Destination") cv.WaitKey(0) def linedraw(): cv.Line(img, (0, 0), (100, 100), (0, 0, 0), 4, 8) display(img, "Destination") cv.WaitKey(0) def drawrectangle():
#!/usr/bin/python import cv2.cv as cv import sys import urllib2 if __name__ == "__main__": cv.NamedWindow("win") if len(sys.argv) > 1: filename = sys.argv[1] im = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_GRAYSCALE) im3 = cv.LoadImage(filename, cv.CV_LOAD_IMAGE_COLOR) else: try: # try opening local copy of image fileName = '../cpp/left01.jpg' im = cv.LoadImageM(fileName, False) im3 = cv.LoadImageM(fileName, True) except: # if local copy cannot be opened, try downloading it url = 'https://raw.github.com/opencv/opencv/master/samples/cpp/left01.jpg' filedata = urllib2.urlopen(url).read() imagefiledata = cv.CreateMatHeader(1, len(filedata), cv.CV_8UC1) cv.SetData(imagefiledata, filedata, len(filedata)) im = cv.DecodeImageM(imagefiledata, cv.CV_LOAD_IMAGE_GRAYSCALE) im3 = cv.DecodeImageM(imagefiledata, cv.CV_LOAD_IMAGE_COLOR) chessboard_dim = (9, 6) found_all, corners = cv.FindChessboardCorners(im, chessboard_dim) print found_all, len(corners) cv.DrawChessboardCorners(im3, chessboard_dim, corners, found_all)
import cv2.cv as cv im = cv.LoadImageM("../img/fruits.jpg", cv.CV_32F) def getDistance(pixel, refcolor): return abs((pixel[0] - refcolor[0]) + (pixel[1] - refcolor[1]) + (pixel[2] - refcolor[2])) refcolor = (0, 0, 0) minDist = 100 for row in range(im.rows): for col in range(im.cols): if getDistance(im[row, col], refcolor) < minDist: im[row, col] = (255, 255, 255) cv.ShowImage("Distance", im) cv.WaitKey(0)