Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42463
| Path | csiph.com!usenet.pasdenom.info!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <insideshoes@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'tree': 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; 'skip:o 50': 0.09; 'trees': 0.09; 'def': 0.12; '"w")': 0.16; '>>': 0.16; '49,': 0.16; '65536': 0.16; 'add,': 0.16; 'dictionaries': 0.16; 'dot,': 0.16; 'itertools': 0.16; 'nameerror:': 0.16; 'numpy': 0.16; '8bit%:5': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'error': 0.23; 'math': 0.24; 'skip:" 30': 0.26; 'defined': 0.27; 'points': 0.29; 'message-id:@mail.gmail.com': 0.30; '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; 'received:google.com': 0.35; 'done': 0.36; 'thanks': 0.36; 'skip:& 10': 0.38; '8bit%:4': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'skip:& 20': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'skip:c 50': 0.60; 'mentioned': 0.61; 'traffic': 0.61; 'name': 0.63; '8bit%:10': 0.64; 'road': 0.65; 'floor,': 0.68; 'dict.': 0.84; 'gray': 0.84; 'poles': 0.84; 'trunks': 0.84; 'buildings': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=Z0XJA63ggS4qb3sL+q3QJkCSfPifsDmDcHXKrWCYeKw=; b=SrX0M+KAqT6Z1Y0iLN42i0IVYHp4h97wtSst6T8LjTn4Hg+0ZrEuT7MOOBIrOpC0Fb KfH690KuBKVWdr/QA4rpfWFLp6wYSQjR9j2Z7mH1L6kmG0TzM6HVQQ6CH/HgjZNeOFqj OPwD53tv43FOYfTZQKVwxa6m2kVDJHHMK6JQYEiur/Lrzw9XkL+IoX/XnFCH4F7CblDT LPJ7z5NuebMfNEbhLNTwpVYRHWeUaZqnjGAJOSRr/IPHCOG66Buil5nGsd059wS3pvD1 H12ac+79oZNxL8usCKwnM0SKy+B3HwZnvk043fpzjrg3KT4MhWSXUwTQB8xKHm2OCrR7 kjbQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.13.39 with SMTP id e7mr3449786igc.97.1364824232570; Mon, 01 Apr 2013 06:50:32 -0700 (PDT) |
| Date | Mon, 1 Apr 2013 19:20:32 +0530 |
| Subject | Error in working with Dict |
| From | inshu chauhan <insideshoes@gmail.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | multipart/alternative; boundary=089e011605e09039d104d94ce726 |
| 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.4056.1364824236.2939.python-list@python.org> (permalink) |
| Lines | 165 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364824236 news.xs4all.nl 6909 [2001:888:2000:d::a6]:49474 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:42463 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
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!!!!
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Error in working with Dict inshu chauhan <insideshoes@gmail.com> - 2013-04-01 19:20 +0530
csiph-web