Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Monday, April 15, 2013
Configuration.AppSettings getting null in C# class library
Default configuration for class library is the configuration file of the application that is consuming it. For example, if it is web application, then move your configurations to web.config.
Wednesday, March 6, 2013
An unhandled exception of type 'Emgu.CV.Util.CvException' occurred in Emgu.CV.dll Additional information: OpenCV: Unknown array type
To fix this issue, check whether the number of columns, rows and channels of source matrix match with the destination matrix.
When converting from OpenCV to EmguCV:
CV_32FC1 means 32 bit floating point single channel matrix
When converting from OpenCV to EmguCV:
CV_32FC1 means 32 bit floating point single channel matrix
Saturday, March 2, 2013
An unhandled exception of type 'Emgu.CV.Util.CvException' occurred in Emgu.CV.dll Additional information: OpenCV: type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in BOWImgDescriptorExtractor
Make sure the feature extractor used to generate vocabulary and the extractor given for BOWImgDescriptorExtractor are of same type. (E.g., SIFT)
More info:
http://stackoverflow.com/questions/15181699/error-in-bowimgdescriptorextractor-in-emgucv
http://code.opencv.org/issues/1879
More info:
http://stackoverflow.com/questions/15181699/error-in-bowimgdescriptorextractor-in-emgucv
http://code.opencv.org/issues/1879
Sunday, December 2, 2012
Content Extraction and Context Inference based Information Retrieval
Final year research project
Abstract
At present, most of the information retrieval mechanisms consider only exact matches of
textual metadata such as topics, manual tags and descriptions etc. These methods are yet to
provide the right information to match the level of human intuition driven relevance. The main
contributor to such factors is due to the lack of assessing relevance of the content and context
of the available data in a unified manner.
Extracting semantic content and inferring knowledge from low level features has always been a major challenge because of the well-known semantic gap issue.
The proposed solution strives to overcome the above mentioned difficulty by providing a framework based approach using machine learning and knowledge representation where right information can be retrieved regardless of the content format or contextual discrepancies. Given that information can be embedded as any content format, the proposed framework analyzes and provides a set of content and context descriptors which can be used in any information retrieval application.
Extracting semantic content and inferring knowledge from low level features has always been a major challenge because of the well-known semantic gap issue.
The proposed solution strives to overcome the above mentioned difficulty by providing a framework based approach using machine learning and knowledge representation where right information can be retrieved regardless of the content format or contextual discrepancies. Given that information can be embedded as any content format, the proposed framework analyzes and provides a set of content and context descriptors which can be used in any information retrieval application.
Key Words:
Information Retrieval, Computer Vision, Ontology, Development Framework
Information Retrieval, Computer Vision, Ontology, Development Framework
Literature Review
In spite of exponential growth of information, which comes in various forms such as video,
image and audio, modern information retrieval mechanisms still use manual, text based
metadata such as topic, tags and description to provide relevant results to user queries.
Actual content and its associated context are not considered by information retrieval mechanisms
when assessing relevance of the search result to the given user query.
Accordingly, modern information retrieval systems are yet far beyond from the way human instinct would assess relevance of the information.
Considering existing products, given a sample image or audio, Query By Example (QBE)
methods have been suggested to find similar content by analyzing and matching the actual
content. However, in this approach matching is done between low level features.
It is difficult
for user to match the search intention in close proximity to the respective low level features,
which results in significant semantic information loss. Ontology driven methods are invented to
provide semantic analysis of the information using an underlying knowledge base. However,
these solutions are either text or web content based.
Each actual content representation and its associated context hold equal value when weighing
relevance of information to the user. So, due to the information loss that can incur by only
considering the text, relevance of the results is greatly reduced. Further, to bridge the gap
between human cognitive way of information retrieval and automatic information retrieval,
machines should simulate this behavior by analyzing the obtainable audio, visual content.
Even though it is evident that visual information such as image and video helps user to
understand a particular concept more realistically with less effort, no research has been done
to find a collective way of processing visual information along with text and audio and infer the
associated context.
After an extensive study on the research being done on this area it is found that, extracting
semantic concepts from low level observable features has always been a major challenge due
to the well-known semantic gap issue.
When it comes to feature detection and extraction of visual information, local features are
preferred over global features to avoid back ground clutter. With the advent of scale invariant
feature detectors and descriptors such as SIFT and SURF, object detection and recognition task
has improved drastically with invariance to scale, rotation and illumination. Also, due to the
high dimensionality of these descriptors, distinctiveness is greatly improved. Bag of visual
Words model has adopted the above advantages in its application on semantic object
detection.
During the evaluation of different content processing mechanisms for image, video and audio,
it is found that even though the processing mechanism for each content format differs from
each other, all of them have a common flow namely, pre-processing, feature detection, feature
extraction and semantic concept detection.
Once the semantic concepts are extracted from the low level features, context should be inferred for a given set of concepts to further refine the solution.
Once the semantic concepts are extracted from the low level features, context should be inferred for a given set of concepts to further refine the solution.
Wide range of context inferring approaches is considered namely, Natural Language Processing
(NLP), Logic based methods (formal logic, predicate logic), Fuzzy reasoning, Probabilistic
methods (Bayesian Reasoning) and semantic networks.
Semantic networks are designated as
the main technique to infer the context, yet no sufficient algorithm was encountered to meet
the exact requirement. Further, author discovered that concept of fuzzy reasoning can be used
to assess relevance in form of gradual transition between falsehood to truth during application
in information retrieval.
Considering the above given aspects, it is concluded that the suggested solution for the
problem domain is unique and feasible, yet immensely challenging due to its limitations in
feature extraction techniques to bridge semantic gap issue, especially for a wide domain.
Further, limitation on available algorithms for context inference has made it even more time
consuming and thought provoking.
High Level Design
Rich Picture in Information Retrieval Application
High Level Architecture
Data Flow
Class Diagram (Framework Design)
Implementation
Content Negotiation
Content Extraction
- Image/ video processing tool: OpenCV (EmguCV)
- Algorithms: Bag of visual words model, SIFT/ SURF for visual feature detection and extraction, K-means for feature clustering, Naive Bayes for classification
SIFT/ SURF Algorithm comparison
Visual word histograms for similar concepts
Context Inference
Context inference for ambiguous scenarios
Semantic network: WordNet
Application in Information Retrieval
Once content and context descriptors are retrieved from the framework, they can be used in
many applications. One such application is given here.
Literal relatedness between user context and content context can be derived using relevance
decision factor.
This measure can be used to assess the relevance of the available content to a
particular user.
For example, user context can be presented in different forms such as
profession, personal interests and present short term search intention. Content context can be
metadata of the available content.
Testing and Evaluation
Precision and recall has been used in many information retrieval
applications to assess relevance.
For testing, test cases were derived according to the given criteria for each component. Training and ground truth images were taken from Google images and Flickr.
Accuracy of the concept detection for images with different variations such as scale, illumination and back ground clutter were tested.
Context inference component was tested for different threshold values to get quantitative measures for relevance such as precision and recall.
Then, non-functional testing was performed. Test results indicate that the implementation of prototype is successful.
Further, critical evaluation was performed with participation of domain experts from academic or technical background. Participants confirmed that the suggested approach helps to improve the relevance of information retrieval and thus it is a timely need.
For testing, test cases were derived according to the given criteria for each component. Training and ground truth images were taken from Google images and Flickr.
Accuracy of the concept detection for images with different variations such as scale, illumination and back ground clutter were tested.
Context inference component was tested for different threshold values to get quantitative measures for relevance such as precision and recall.
Then, non-functional testing was performed. Test results indicate that the implementation of prototype is successful.
Further, critical evaluation was performed with participation of domain experts from academic or technical background. Participants confirmed that the suggested approach helps to improve the relevance of information retrieval and thus it is a timely need.
Future Enhancements
-
- Support different content processing mechanisms for same content type (E.g., Research papers and new paper given as text content)
- Different processing modules such as audio and web content can be implemented and plugged in to the framework
- Fusion of audio words with visual content can be used to improve the accuracy of semantic concept recognition in video content
- Scale and evaluate the performance on a realistic database
Tuesday, October 9, 2012
Difference between "override" and "new" keyword
"New" modifier is used to hide a member inherited from a parent class which is not virtual. This does not have the polymorphic behavior, so if someone calls the parent class method, the implementation in the method which "new" modifier has been used is not been called.
"Override" modifier can be used to override virtual or abstract members and it contains the polymorphic behavior.
"Override" modifier can be used to override virtual or abstract members and it contains the polymorphic behavior.
Wednesday, September 26, 2012
System.InvalidOperationException in NUnit with RhinoMocks
To solve the above exception while running unit tests, you need to make sure that all the mocked methods are using "virtual" keyword in method signature.
Ex: Public virtual method(int a, int b)
The reason for this issue is, Rhino mocks creates a proxy class when you call StrictMock (or any type) using MockRepository. Then, it needs to extend your type.
By making the methods as virtual we let RhinoMocks know that they can override and inherit it for their mocking purposes.
Ex: Public virtual method(int a, int b)
The reason for this issue is, Rhino mocks creates a proxy class when you call StrictMock (or any type) using MockRepository. Then, it needs to extend your type.
By making the methods as virtual we let RhinoMocks know that they can override and inherit it for their mocking purposes.
Tuesday, April 17, 2012
How to fix "TypeInitializationException"?
This exception is thrown as a wrapper around the exception thrown by the class initializer.
Best thing is to check the inner exception details. (View details)
I got the following exception:
The type initializer for 'Antlr.StringTemplate.StringTemplate' threw an exception
Due to one assembly missing:
Best thing is to check the inner exception details. (View details)
I got the following exception:
The type initializer for 'Antlr.StringTemplate.StringTemplate' threw an exception
Due to one assembly missing:
{"Could not load file or assembly 'antlr.runtime,
Version=2.7.7.3, Culture=neutral, PublicKeyToken=d7701e059243744f' or one of
its dependencies. The system cannot find the file specified.":"antlr.runtime,
Version=2.7.7.3, Culture=neutral, PublicKeyToken=d7701e059243744f"}
I could fix this after I add antlr.runtime dll as a reference to the project.Wednesday, February 29, 2012
Nested IF conditions vs Single line IF with AND operation
In C#, compiler will generate the same MSIL code for following code chunks.
Single line IF
if ( A && B ){
// Do something;
}
Nested IF
if ( A ){
if ( B ) {
// Do something;
}
}
Single line IF
if ( A && B ){
// Do something;
}
Nested IF
if ( A ){
if ( B ) {
// Do something;
}
}
Monday, February 27, 2012
How to fix TypeLoadException was unhandled Error?
Problem: I got the following runtime error while debugging my application.
TypeLoadException was unhandled
"Evaluate" is an interface method defined in a different project (Assembly A) and implemented in another project. (Assembly B).
Then I saw following warning message in the Error list:
Warning: Found conflicts between different versions of the same dependent assembly.
The given assembly name (Assembly C) for the above warmning is referenced by both Assembly A and Assembly B. It is a third party dll. Also, Assembly A is referenced by Assembly B.
Once I double clicked on the warning, it prompted me saying "One or more dependent assemblies have version conflicts. Do you want to fix these conflicts by adding binding redirect records in the app.config file?
Then, once I accepted that, the code chunk given below was automatically added to my App.config file.
Consequently, that has fixed the issue!
But I suspected that there can be some unused dlls as the above App.config entry is redirecting all assembly binding references for versions 0.0.0.0 to 3.1.3.42154 (the latest) to version 3.1.3.42154 dll. This should happen as you can't load multiple versions of the same assembly in the same app domain. So, without binding redirect, an attempt to load a different version of an already loaded assembly will fail.
Since the above code chunk sounds like a workaround to overcome the issue, I revisited the code to find the actual reason for the exception.
There, I could find that different versions of the same dll is used in two dependent projects.
So, when I refer the third party dll (Assembly C) from the same folder, same version, and remove the code chunk in the App.config, I did not get the "TypeLoadException" issue.
After doing some research on this I found that this may occur if you have an interface in one assembly and it's implementation in another, and the implementation assembly was build against a different version of the interface.
Also, this issue can occur if you load assembly dynamically using LoadFrom(string) method. I used LoadFrom method to invoke Assembly B.
Also, the project dependency given above is called as "diamond shaped" dependency which may cause this issue.
However, the error message is little bit mis-leading, but we can get some clue out of that. Exception can occur even the method is not executed during the runtime.
TypeLoadException was unhandled
"Evaluate" is an interface method defined in a different project (Assembly A) and implemented in another project. (Assembly B).
Then I saw following warning message in the Error list:
Warning: Found conflicts between different versions of the same dependent assembly.
The given assembly name (Assembly C) for the above warmning is referenced by both Assembly A and Assembly B. It is a third party dll. Also, Assembly A is referenced by Assembly B.
Once I double clicked on the warning, it prompted me saying "One or more dependent assemblies have version conflicts. Do you want to fix these conflicts by adding binding redirect records in the app.config file?
Then, once I accepted that, the code chunk given below was automatically added to my App.config file.
Consequently, that has fixed the issue!
But I suspected that there can be some unused dlls as the above App.config entry is redirecting all assembly binding references for versions 0.0.0.0 to 3.1.3.42154 (the latest) to version 3.1.3.42154 dll. This should happen as you can't load multiple versions of the same assembly in the same app domain. So, without binding redirect, an attempt to load a different version of an already loaded assembly will fail.
Since the above code chunk sounds like a workaround to overcome the issue, I revisited the code to find the actual reason for the exception.
There, I could find that different versions of the same dll is used in two dependent projects.
So, when I refer the third party dll (Assembly C) from the same folder, same version, and remove the code chunk in the App.config, I did not get the "TypeLoadException" issue.
After doing some research on this I found that this may occur if you have an interface in one assembly and it's implementation in another, and the implementation assembly was build against a different version of the interface.
Also, this issue can occur if you load assembly dynamically using LoadFrom(string) method. I used LoadFrom method to invoke Assembly B.
Also, the project dependency given above is called as "diamond shaped" dependency which may cause this issue.
However, the error message is little bit mis-leading, but we can get some clue out of that. Exception can occur even the method is not executed during the runtime.
Tuesday, October 25, 2011
Do we need to pass a reference type argument to a method using REF keyword? - Part 02
Consider the following reference type variable x:
ArrayList x = new ArrayList()
Here, assume memory location of x is 2110 and it points to the memory location of the new object which can be 1110.
So, if you pass x variable to a method by reference without giving REF keyword, a copy of the reference, which resides in memory location 3110 is passed to the method with the value of 1110 which points to the same object.
But if you pass x variable to a method with REF keyword the original reference itself will be copied which in this case 2110.
For more info: when we should use REF keyword? - Part 01
ArrayList x = new ArrayList()
Here, assume memory location of x is 2110 and it points to the memory location of the new object which can be 1110.
So, if you pass x variable to a method by reference without giving REF keyword, a copy of the reference, which resides in memory location 3110 is passed to the method with the value of 1110 which points to the same object.
But if you pass x variable to a method with REF keyword the original reference itself will be copied which in this case 2110.
For more info: when we should use REF keyword? - Part 01
Monday, October 24, 2011
How to give quotation mark in C# String?
Use backslash ahead of the string you need to quote
Ex: string quotationMark = "\" Hi! \"";
Ex: string quotationMark = "\" Hi! \"";
Sunday, October 23, 2011
How to fix System.BadImageFormatException in 64-bit OS?
If you try to refere a dll which has a file format which CLR does not support, you will get this exception. In 64 bit OS, this can happen due to dll is having some 32 bit parts (COM components etc.) and it is being loaded as a 64 bit module.
To avoid that, you need to do the following:
To avoid that, you need to do the following:
- In Visual Studio, right click the project.
- In project properties, go to 'Build' tab
- In General section, select Platform target as x86 (default is 'Any CPU')
- Recompile the project and execute
Friday, September 16, 2011
When we should use REF keyword to pass a reference type argument?
If a value type (ex: int) is passed to a method, by default a copy of the value is being passed as argument and any change applied to that variable will not be applied to the original variable. If you want those changes to be there in original variable, you need to pass the argument using REF keyword.
Any programmer would be familiar with this scenario.
Do we need to pass a reference type argument to a method using REF keyword?
It depends on the type of change you are willing to do in your method.
If we only want to change the state of the object the REF keyword is not required.
But if you want to assign a new value to the variable in method and if it should represent in original variable, you should use REF keyword.
Why?
In C#, everytihng is passed by value. Even if it is a reference type, copy of the reference is passed to the variable by default. However, if you use REF keyword, the original reference will be passed to the method, thus representing all the changes you do in the method variable in the original variable.
Example:
public class Student
int ID {get; set;}
Student stud1 = new Student(1);
// Assign a new object (Stud2) with ID = 2 - assign object to a new object
changeObjectByVal ( stud1); // stud1 ID value remains as 1
changeObjectByRef ( ref stud1); // stud1 ID value will be 2
// Change ID value to 3 - changing the object's state
changeObjectAttrByVal (stud1); // stud1 ID value will be 3
changeObjectAttrByRef (stud1); // stud1 ID value will be 3
Any programmer would be familiar with this scenario.
Do we need to pass a reference type argument to a method using REF keyword?
It depends on the type of change you are willing to do in your method.
If we only want to change the state of the object the REF keyword is not required.
But if you want to assign a new value to the variable in method and if it should represent in original variable, you should use REF keyword.
Why?
In C#, everytihng is passed by value. Even if it is a reference type, copy of the reference is passed to the variable by default. However, if you use REF keyword, the original reference will be passed to the method, thus representing all the changes you do in the method variable in the original variable.
Example:
public class Student
int ID {get; set;}
Student stud1 = new Student(1);
// Assign a new object (Stud2) with ID = 2 - assign object to a new object
changeObjectByVal ( stud1); // stud1 ID value remains as 1
changeObjectByRef ( ref stud1); // stud1 ID value will be 2
// Change ID value to 3 - changing the object's state
changeObjectAttrByVal (stud1); // stud1 ID value will be 3
changeObjectAttrByRef (stud1); // stud1 ID value will be 3
Wednesday, September 14, 2011
Case insensitive string comparison
What will happen if you compare following two strings using equality operator (==)?
string a = "jayani";
string b = "Jayani"
a == b - False
It will say that two strings are not the same.
But what if you want to compare them in a case insensitive manner?
You can use String.Compare method for that.
String.Compare(a, b, true); // This will return zero which indicates that strings are similar.
Third parameter asks to do a case insensitive comparison.
string a = "jayani";
string b = "Jayani"
a == b - False
It will say that two strings are not the same.
But what if you want to compare them in a case insensitive manner?
You can use String.Compare method for that.
String.Compare(a, b, true); // This will return zero which indicates that strings are similar.
Third parameter asks to do a case insensitive comparison.
Tuesday, September 13, 2011
My first day with LINQ! :)
Today I got to know about LINQ - Language Integration Query, in the same way Marie Curie found Radium (I think I can remember the correct story..May be not her!)
I had two arrays in my hand and I wanted to compare them and see whether they are equel. But I can't use the object's Equels method as it compares the memory location rather than the value as Array is a reference type.
I could easily write a for-loop to achieve this but I wanted something new other than the old-fashioned for-loop...
There, I found LINQ!!! (Well.. I know I did not invent that, but Radium is also something that already existed rite? :P)
I could use LINQ join to achieve this. Here's the query I used:
private static bool CompareArrayOrder(string[] arr1, string[] arr2){
var q = from a in arr1
join b in arr2 on a equals b
select a;
return(arr1.Length == arr2.Length && q.Count() == arr1.Length);}
LINQ is something that you can map data with your objects such as arrays.
So, why use LINQ instead of for loop?
For the time being, what I know is, it ROCKS and COOLER than using for loops!
Other than that it makes your code simpler and less cumbersome thus making it easier to read.
I had two arrays in my hand and I wanted to compare them and see whether they are equel. But I can't use the object's Equels method as it compares the memory location rather than the value as Array is a reference type.
I could easily write a for-loop to achieve this but I wanted something new other than the old-fashioned for-loop...
There, I found LINQ!!! (Well.. I know I did not invent that, but Radium is also something that already existed rite? :P)
I could use LINQ join to achieve this. Here's the query I used:
private static bool CompareArrayOrder(string[] arr1, string[] arr2){
var q = from a in arr1
join b in arr2 on a equals b
select a;
return(arr1.Length == arr2.Length && q.Count() == arr1.Length);}
LINQ is something that you can map data with your objects such as arrays.
So, why use LINQ instead of for loop?
For the time being, what I know is, it ROCKS and COOLER than using for loops!
Other than that it makes your code simpler and less cumbersome thus making it easier to read.
Does StringBuilder always better than String in string concatenation?
No.
Why?
Use StringBuilder if you are creating a long string using a loop, when the number of string are high.
Do not use StringBuilder for small number of strings becuase, it makes the code less manageable and StringBuilder contains more logic than string, when it comes to processing the string.
Why?
Use StringBuilder if you are creating a long string using a loop, when the number of string are high.
Do not use StringBuilder for small number of strings becuase, it makes the code less manageable and StringBuilder contains more logic than string, when it comes to processing the string.
Thursday, September 8, 2011
Why Trim() function ignore specified characters?
Trim() function in String will trim the preceding and trailing characters of a given character array until it finds a character which is not there in the given array.
Example:
char[] t = new char[] { 1, 2, 3}
trim("12external319test23");
result is "external319test".
So, if it is posible to have spaces, commas etc. as leading or trailing characters in addition to the defined character set, add them also to the character array, before you call Trim() function.
Example:
char[] t = new char[] { 1, 2, 3}
trim("12external319test23");
result is "external319test".
So, if it is posible to have spaces, commas etc. as leading or trailing characters in addition to the defined character set, add them also to the character array, before you call Trim() function.
Wednesday, August 31, 2011
Stack Overflow Exception
Today I got a stack overflow exception, because I have written a recursive function to be called each time with the same conditions thus creating an infinite recursion.
Why Stack Overflow?
This exception occurs when too much memory is used by call stack and consequently it is running out of the allocated memory space. Call stack contains the execution flow of the computer program.
Why Stack Overflow?
This exception occurs when too much memory is used by call stack and consequently it is running out of the allocated memory space. Call stack contains the execution flow of the computer program.
Thursday, August 11, 2011
Using StringBuilder for string concatenation
It is being said that you should always use StringBuilder object to append strings. But you can simply do the same thing using an overloaded + or += operator. Once you compile the program, compiler will tranform the + operator to String.Concat.
So why we should use StringBuilder?
The reason is String is an immutable object, which means if you create a string once you cannot change it again. So, if you keep appending several strings, it will create lot of unnessasary temporary strings in memory.
To clean them up, garbage collection needs to run more often - resulting an additional overhead.
Unlike String, StringBuilder is mutable, so it will reduce the no of temporary objects you create in memory.
Consequently, it will make appending faster than the String.
So why we should use StringBuilder?
The reason is String is an immutable object, which means if you create a string once you cannot change it again. So, if you keep appending several strings, it will create lot of unnessasary temporary strings in memory.
To clean them up, garbage collection needs to run more often - resulting an additional overhead.
Unlike String, StringBuilder is mutable, so it will reduce the no of temporary objects you create in memory.
Consequently, it will make appending faster than the String.
Avoid unneccassary scope allocation
If you have variables which are not used outside the class, but declared as Public, you should avoid that practice. Declare them as Private. Also, if you have variables which are accesed only with in a particular method, do not declare them in class scope. Define them only in method scope.
Either way we can access the variables to get what we want. Then, why we need to follow this?
Why?
It optimizes memory allocation. For arguments, memory is allocated as stack frames. Once you go out of the scope of variable, the memory allocated for that variable is released. So, more scope you allocate for variables, more memory will be required to hold them.
Either way we can access the variables to get what we want. Then, why we need to follow this?
Why?
It optimizes memory allocation. For arguments, memory is allocated as stack frames. Once you go out of the scope of variable, the memory allocated for that variable is released. So, more scope you allocate for variables, more memory will be required to hold them.
Subscribe to:
Posts (Atom)














