Archive
Using an #API to Retrieve User Details from a #QQ Account ID

QQ, one of China’s largest instant messaging platforms, assigns each user a unique account ID. If you need to retrieve user details from a QQ account ID programmatically, you can use an API such as AvatarAPI. This guide will walk you through making an API request and interpreting the returned JSON response.
API Endpoint
The API request is made to the following URL:
https://avatarapi.com/v2/api.aspx
Request Format
The API expects a POST request with a JSON body containing authentication details (username and password) along with the QQ email ID of the user you want to retrieve information for.
Example Request Body
{
"username": "demo",
"password": "demo___",
"email": "16532096@qq.com"
}
Sending the Request
You can send this request using cURL, Postman, or a programming language like Python. Here’s an example using Python’s requests library:
import requests
import json
url = "https://avatarapi.com/v2/api.aspx"
headers = {"Content-Type": "application/json"}
payload = {
"username": "demo",
"password": "demo___",
"email": "16532096@qq.com"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json())
API Response
The API returns a JSON object with the user’s details. Below is a sample response:
{
"Name": "邱亮",
"Image": "https://q.qlogo.cn/g?b=qq&nk=16532096&s=640",
"Valid": true,
"City": "",
"Country": "China",
"IsDefault": true,
"Success": true,
"RawData": "",
"Source": {
"Name": "QQ"
}
}
Explanation of Response Fields
- Name: The user’s name associated with the QQ account.
- Image: A URL to the user’s QQ avatar image.
- Valid: Boolean flag indicating if the QQ account is valid.
- City: The user’s city (if available).
- Country: The user’s country.
- IsDefault: Indicates whether the profile is using the default avatar.
- Success: Boolean flag indicating whether the API request was successful.
- RawData: Any additional raw data returned from the source.
- Source: The data provider (in this case, QQ).
Use Cases
This API can be useful for:
- Enhancing user profiles by fetching their QQ avatar and details.
- Verifying the validity of QQ accounts before allowing user actions.
- Personalizing content based on user identity from QQ.
Conclusion
Using an API to retrieve QQ user details is a straightforward process. By sending a POST request with the QQ email ID, you can obtain the user’s name, avatar, and other details. Ensure that you handle user data responsibly and comply with any relevant privacy regulations.
For production use, replace the demo credentials with your own API key and ensure secure storage of authentication details.
C# – using #OpenCV to determine if an image contains an image of a car (or a duck)

TL;DR; Here is the repo: https://github.com/infiniteloopltd/IsItACar
This demo application can take an image and derermine if the image is that of a Car, or not a car. My test image was of a duck, which was very defintely not car-like. But sillyness aside, this can be very useful for image upload validation – if you want to ensure that your car-sales website doesn’t allow their users to upload nonsense pictures, but only of cars, then this code could be useful.
Why Use Emgu.CV for Computer Vision?
Emgu.CV simplifies the use of OpenCV in C# projects, providing an intuitive interface while keeping the full functionality of OpenCV. For tasks like object detection, it is an ideal choice due to its performance and flexibility.
Prerequisites
Before diving into the code, make sure you have the following set up:
- Visual Studio (or another preferred C# development environment)
- Emgu.CV library installed via NuGet:
- Search for
Emgu.CVandEmgu.CV.runtime.windowsin the NuGet Package Manager and install them.
- Search for
Setting Up Your Project
We’ll write a simple application to detect cars in an image. The code uses a pre-trained Haar cascade classifier, which is a popular method for object detection.
The Code
Here’s a complete example demonstrating how to load an image from a byte array and run car detection using Emgu.CV:
csharpCopy codeusing Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System;
using System.Drawing;
using System.IO;
class Program
{
static void Main(string[] args)
{
// Load the image into a byte array (this could come from a database or API)
byte[] imageBytes = File.ReadAllBytes("path_to_your_image.jpg");
// Create a Mat object to hold the decoded image
Mat mat = new Mat();
// Decode the image from the byte array into the Mat object
CvInvoke.Imdecode(imageBytes, ImreadModes.Color, mat);
// Convert the Mat to an Image<Bgr, byte> for further processing
Image<Bgr, byte> image = mat.ToImage<Bgr, byte>();
// Load the Haar cascade for car detection
string cascadeFilePath = "path_to_haarcascade_car.xml"; // Download a Haar cascade for cars
CascadeClassifier carClassifier = new CascadeClassifier(cascadeFilePath);
// Convert to grayscale for better detection performance
using (var grayImage = image.Convert<Gray, byte>())
{
// Detect cars in the image
Rectangle[] cars = carClassifier.DetectMultiScale(
grayImage,
scaleFactor: 1.1,
minNeighbors: 5,
minSize: new Size(30, 30));
// Draw rectangles around detected cars
foreach (var car in cars)
{
image.Draw(car, new Bgr(Color.Red), 2);
}
// Save or display the image with the detected cars
image.Save("output_image_with_cars.jpg");
Console.WriteLine($"Detected {cars.Length} car(s) in the image.");
}
}
}
Breaking Down the Code
- Loading the Image as a Byte Array:csharpCopy code
byte[] imageBytes = File.ReadAllBytes("path_to_your_image.jpg");Instead of loading an image from a file directly, we load it into a byte array. This approach is beneficial if your image data is not file-based but comes from a more dynamic source, such as a database. - Decoding the Image:csharpCopy code
Mat mat = new Mat(); CvInvoke.Imdecode(imageBytes, ImreadModes.Color, mat);We useCvInvoke.Imdecodeto convert the byte array into aMatobject, which is OpenCV’s matrix representation of images. - Converting
MattoImage<Bgr, byte>:csharpCopy codeImage<Bgr, byte> image = mat.ToImage<Bgr, byte>();TheMatis converted toImage<Bgr, byte>to make it easier to work with Emgu.CV functions. - Car Detection Using Haar Cascades:csharpCopy code
Rectangle[] cars = carClassifier.DetectMultiScale(grayImage, 1.1, 5, new Size(30, 30));The Haar cascade method is used for object detection. You’ll need to download a Haar cascade XML file for cars and provide the path. - Drawing Detected Cars:csharpCopy code
image.Draw(car, new Bgr(Color.Red), 2);Rectangles are drawn around detected cars, and the image is saved or displayed.
Downloading Haar Cascade for Cars
To detect cars, you need a pre-trained Haar cascade file. You can find these files on the OpenCV GitHub repository or by searching online for “haarcascade for car detection.”
Conclusion
This example demonstrates a simple yet powerful way to use Emgu.CV for car detection in C#. While Haar cascades are efficient, modern machine learning methods like YOLO or SSD are more accurate for complex tasks. However, for basic object detection, this approach is easy to implement and performs well for simpler use cases.
Feel free to experiment with different parameters to improve detection accuracy or try integrating more advanced models for more complex scenarios. Happy coding!