Esempio n. 1
0
def draw_target(img, x, y, color_name):

	width = 10
	if color_name == "GREEN":
		color = cv.CV_RGB(0,255,0)
	else:
		color = cv.CV_RGB(255,0,0)

	size = cv.cvGetSize(img)
	if x >= size.width or x < 0 or y >= size.height or y < 0:
		return

	for i in range(width):
		for j in range(width):
			if i==0 or j==0 or j==9 or i==9:
				px = x + j - width/2
				py = y + i - width/2

				if px<0:
					px = 0
				if py<0:
					py = 0
				if px>=size.width:
					px = size.width-1
				if py>=size.height:
					py = size.height-1		

				cv.cvSet2D(img,py,px,color)
Esempio n. 2
0
 def __link(self):
     myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
     kkk = 0
     self.edges = []
     for curve in self.allcurve:
         showpt = []
         state = 0
         currentPoint = None
         currentPointIdx = -1
         cumulate = 0
         dcurve = curve + curve
         curlen = len(curve)
         ptcount = 0
         pointseq = []
         for c in dcurve:
             if (ptcount > curlen): break
             cumulate += 1
             for kk in range(len(self.points)):
                 k = self.points[kk]
                 if (abs(c.x - k.x) + abs(c.y - k.y) < 15):
                     if (currentPoint != k or cumulate > 40):
                         state += 1
                         currentPoint = k
                         currentPointIdx = kk
                         cumulate = 0
                         pointseq.append(kk)
             if (state > 0):
                 showpt.append([c, state, currentPointIdx])
                 ptcount += 1
         if (state > 1):
             kkk += 1
             cnt = 0
             pret = -1
             e = None
             for s, t, cp in showpt:
                 if (cp != pret):
                     if e != None:
                         e.end = cp
                     e = Edge()
                     self.edges.append(e)
                     e.start = cp
                     pret = cp
                 cnt += 1
                 if (t < state):
                     e.addPoint(s)
                     #print  "%d\t%3.2f\t%3.2f\t%d\t%d\t%d" % (kkk, s.x, s.y, cnt, pointseq[t - 1], pointseq[t])
             e.end = showpt[-1][2]
     print >> OUT, "seq\tptn\tx\ty\t"
     #        self.__edgededup()
     self.__evenSample(self.npoints)
     for ie, e in enumerate(self.edges):
         print "P(%d) <-> P(%d) length %d, selected %d" % (
             e.start, e.end, len(e.points), len(e.selected))
         for d in e.points:
             cv.cvSet2D(self.drawimg, int(d.y), int(d.x), color[3])
         for ip, p in enumerate(e.selected):
             cv.cvDrawCircle(self.drawimg, p, 2,
                             cv.cvScalar(255, 255, 0, 0))
             print >> OUT, "%d\t%d\t%d\t%d" % (ie, ip, p.x, p.y)
Esempio n. 3
0
def putoriginal(fname, img):
    ori_img = highgui.cvLoadImage (fname)
    ori_img_thumb = cv.cvCreateImage(cv.cvSize(ori_img.width/4, ori_img.height/4), 8,3)
    cv.cvResize(ori_img, ori_img_thumb)
    for x in range(ori_img_thumb.height):
        for y in range(ori_img_thumb.width):
            cv.cvSet2D(img, x, y, cv.cvGet2D(ori_img_thumb, x, y))
    return 
Esempio n. 4
0
def putoriginal(fname, img):
    ori_img = highgui.cvLoadImage(fname)
    ori_img_thumb = cv.cvCreateImage(
        cv.cvSize(ori_img.width / 4, ori_img.height / 4), 8, 3)
    cv.cvResize(ori_img, ori_img_thumb)
    for x in range(ori_img_thumb.height):
        for y in range(ori_img_thumb.width):
            cv.cvSet2D(img, x, y, cv.cvGet2D(ori_img_thumb, x, y))
    return
Esempio n. 5
0
    def __link(self):
        myfont = cv.cvInitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5)
        kkk = 0
        self.edges = []
        for curve in self.allcurve:
            showpt = []
            state = 0  
            currentPoint = None 
            currentPointIdx = -1
            cumulate = 0
            dcurve = curve + curve
            curlen = len(curve)
            ptcount = 0
            pointseq = []
            for c in dcurve:
                if (ptcount > curlen): break
                cumulate += 1
                for kk in range(len(self.points)):
                     k = self.points[kk]
                     if (abs(c.x - k.x) + abs(c.y - k.y) < 15):
                          if (currentPoint != k or cumulate > 40):
                              state += 1
                              currentPoint = k
                              currentPointIdx = kk
                              cumulate = 0
                              pointseq.append(kk)
                if (state > 0):
                     showpt.append([c, state, currentPointIdx])
                     ptcount += 1
            if (state > 1):
                kkk += 1
                cnt = 0
                pret = -1
                e = None 
                for s,t, cp in showpt:
                    if (cp != pret):
                        if e != None:
                             e.end = cp
                        e = Edge()
                        self.edges.append(e)
                        e.start = cp 
                        pret = cp 
                    cnt += 1
                    if (t < state):
                         e.addPoint(s)
                         #print  "%d\t%3.2f\t%3.2f\t%d\t%d\t%d" % (kkk, s.x, s.y, cnt, pointseq[t - 1], pointseq[t])
                e.end = showpt[-1][2]
        print >> OUT, "seq\tptn\tx\ty\t" 
#        self.__edgededup()
        self.__evenSample(self.npoints)
        for ie, e in enumerate(self.edges):
            print  "P(%d) <-> P(%d) length %d, selected %d" % (e.start, e.end, len(e.points), len(e.selected))
            for d in e.points:
                cv.cvSet2D(self.drawimg, int(d.y), int(d.x), color[3])
            for ip, p in enumerate(e.selected):
                cv.cvDrawCircle(self.drawimg, p, 2, cv.cvScalar(255,255,0,0))
                print >> OUT, "%d\t%d\t%d\t%d" % (ie, ip, p.x, p.y) 
Esempio n. 6
0
def show(fr,width,height,name):
    image = cv.cvCreateImage(cv.cvSize (width, height),8,1)
    l = 0
    for j in range(0,image.width):
        for i in range(0,image.height):
            cv.cvSet2D(image,i,j,int(fr[l][0]));
            l=l+1
    highgui.cvShowImage(name,image)
    highgui.cvWaitKey(1000/29)
Esempio n. 7
0
def removeErrantPoints(frame):
    size = cv.cvGetSize(frame)
    
    for x in range(size.width):
        for y in range(size.height):
            if(cv.cvGetReal2D(frame, y, x) > 0):
                count = 0
                count += same2ndValue(frame, x-1, y)
                count += same2ndValue(frame, x+1, y)
                count += same2ndValue(frame, x, y-1)
                count += same2ndValue(frame, x, y+1)
                count += same2ndValue(frame, x-1, y-1)
                count += same2ndValue(frame, x-1, y+1)
                count += same2ndValue(frame, x+1, y-1)
                count += same2ndValue(frame, x+1, y+1)
                if count == 0:
                    cv.cvSet2D(frame, y, x, cv.cvScalar(0, 0, 0, 0))
Esempio n. 8
0
def draw_target(img, x, y):
    width = 10
    color = cv.CV_RGB(0,255,0);

    size = cv.cvGetSize(img)

    #cv.cvSet2D(img,x,y,color);

    for i in range(width):
        for j in range(width):
            if i==0 or j==0 or j==9 or i==9:
                px = x + j - width/2
                py = y + i - width/2
    
                if px<0:
                    px = 0
                if py<0:
                    py = 0
                if px>=size.width:
					px = size.width-1
                if py>=size.height:
                    py = size.height-1

                cv.cvSet2D(img,py,px,color)
Esempio n. 9
0
def draw_target(img, x, y):
    width = 10
    color = cv.CV_RGB(0, 255, 0)

    size = cv.cvGetSize(img)

    #cv.cvSet2D(img,x,y,color);

    for i in range(width):
        for j in range(width):
            if i == 0 or j == 0 or j == 9 or i == 9:
                px = x + j - width / 2
                py = y + i - width / 2

                if px < 0:
                    px = 0
                if py < 0:
                    py = 0
                if px >= size.width:
                    px = size.width - 1
                if py >= size.height:
                    py = size.height - 1

                cv.cvSet2D(img, py, px, color)