Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42464
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <vincent.vandevyvre@swing.be> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'tree': 0.05; 'url:launchpad': 0.05; 'subject:Error': 0.07; 'advance': 0.07; '"__main__":': 0.09; '#print': 0.09; '[0,': 0.09; 'blue': 0.09; 'function,': 0.09; 'pixel': 0.09; 'trees': 0.09; 'def': 0.12; '"w")': 0.16; '49,': 0.16; '65536': 0.16; 'add,': 0.16; 'dictionaries': 0.16; 'dot,': 0.16; 'from:addr:swing.be': 0.16; 'from:addr:vincent.vandevyvre': 0.16; 'from:name:vincent vande vyvre': 0.16; 'itertools': 0.16; 'message-id:@swing.be': 0.16; 'nameerror:': 0.16; 'numpy': 0.16; 'oqapy': 0.16; 'paqager': 0.16; 'received:mobistar.be': 0.16; 'url:oqapy': 0.16; 'url:paqager': 0.16; 'url:qarte': 0.16; 'v.v.': 0.16; '\xe9crit': 0.16; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'math': 0.24; 'skip:" 30': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'getting': 0.31; "skip:' 10": 0.31; 'branches': 0.31; 'initialized': 0.31; 'file': 0.32; 'class': 0.32; 'skip:c 30': 0.32; '(most': 0.33; 'skip:t 40': 0.33; 'subject:with': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'done': 0.36; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'mentioned': 0.61; 'traffic': 0.61; 'name': 0.63; 'road': 0.65; 'floor,': 0.68; 'dict.': 0.84; 'gray': 0.84; 'poles': 0.84; 'trunks': 0.84; 'buildings': 0.91 |
| Date | Mon, 01 Apr 2013 16:10:06 +0200 |
| From | Vincent Vande Vyvre <vincent.vandevyvre@swing.be> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Error in working with Dict |
| References | <CAFqGZRFgAVHTjA+XcoGRg+p2QcGZP_t94tKaem+BWAdj+p0oiQ@mail.gmail.com> |
| In-Reply-To | <CAFqGZRFgAVHTjA+XcoGRg+p2QcGZP_t94tKaem+BWAdj+p0oiQ@mail.gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 8bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4057.1364825410.2939.python-list@python.org> (permalink) |
| Lines | 95 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364825410 news.xs4all.nl 6891 [2001:888:2000:d::a6]:53567 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:42464 |
Show key headers only | View raw
Le 01/04/13 15:50, inshu chauhan a écrit :
> I have this program which is working with 2 dictionaries segments,
> class_counts.. but I am getting an error mentioned below the programme.
>
> import cv
> from itertools import *
> from math import floor, sqrt, ceil
> from numpy import array, dot, subtract, add, outer, argmax, linalg as lin
>
>
> def Computesegclass(segimage, refimage):
> f = open("Pixel_count_with_region_num_trial1.txt", "w")
> segments = {}
> class_count = {}
> for y in xrange(0, segimage.height):
> for x in xrange(0, segimage.width):
>
> if segimage[y,x] == (0.0, 0.0, 0.0):
> continue
> else:
> seg_color = segimage[y,x]
> blue = int(seg_color[0])
> green = int(seg_color[1])
> red = int(seg_color[2])
> region_num = blue + 256 * green + 65536 * red
> #print region_num
> segments[region_num] = segments.setdefault(region_num,
> 0) + 1
> #print segments
>
> class_color = refimage[y,x]
>
> if class_color == (0.0,0.0,0.0):
> class_number = 0 # No class
> elif class_color == (0.0,255.0,0.0):
> class_number = 1 # Trees
> elif class_color == (255.0, 0.0, 128.0):
> class_number = 2 # Buildings
> elif class_color == (0.0,0.0,255.0):
> class_number = 3 # Automobiles
> elif class_color == (255.0, 255.0, 0.0):
> class_number = 4 # Road Points
> elif class_color == (0.0, 64.0, 128.0):
> class_number = 5 # Tree trunks nad branches
> elif class_color == (255.0, 0.0 ,0.0):
> class_number = 6 # Poles
> elif class_color == (255.0, 0.0, 255.0):
> class_number = 7 # Traffic Lights
> else:
> class_number = 0 # Gray Pixel
>
> class_count.setdefault(region_num, [0, 0, 0, 0, 0, 0,
> 0, 0])[class_number] += 1
> # print class_count
> for k in sorted(class_count.iterkeys()):
> i = argmax(class_count[k])
> print >> f, i
>
> if __name__== "__main__":
> segimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters
> Thesis\Segmentation\segmentation_numbers_00000.tif",
> cv.CV_LOAD_IMAGE_UNCHANGED)
> refimage = cv.LoadImageM(r"C:\Users\inshu\Desktop\Masters
> Thesis\Segmentation\Hand_Classified1.tif", cv.CV_LOAD_IMAGE_UNCHANGED)
> print segimage
> Computesegclass(segimage, refimage)
>
>
> ERROR :
>
> Traceback (most recent call last):
> File "C:\Users\inshu\Desktop\seg.py", line 49, in <module>
> for k in sorted(class_count.iterkeys()):
> NameError: name 'class_count' is not defined
>
> I know this error is because I have initialized both dicts inside the
> function, But why dicts are not saved out, if I intialize the dicts
> outside the function, the processing is still done inside and end
> result I am getting is an empty dict.
>
>
> Thanks in Advance for suggestions!!!!
>
>
>
Get the class_count in the return of Computesegclass
cc = Computesegclass(segimage, refimage)
for k in sorted(cc.iterkeys()):
...
--
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Error in working with Dict Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-04-01 16:10 +0200
csiph-web